# Add Error Prone to a Maven Build

Yes. An agent wires Error Prone into your Maven compiler plugin on the JDKs that support it, fixes or suppresses what it reports with reasons, and opens a PR.

[Run this on Rush](https://cloud.getrush.ai/run/add-errorprone/maven/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent reads the build before it adds a compiler plugin. In a library laid out like jhy/jsoup, `pom.xml` pins `maven-compiler-plugin` 3.16.0 with the default `compile` and `testCompile` executions disabled and replaced by named ones: `compile-package-info` builds the `package-info.java` files at source 8, a `java-8` profile activated on JDK 1.8 compiles the base with `-source 1.8`, and a `multi-release` profile activated on JDK 11 and up compiles the base with `<release>8</release>`, an overlay from `src/main/java11` with `<release>11</release>` and `multiReleaseOutput`, and the tests at release 11 with `src/test/java11` added by `build-helper-maven-plugin`. `animal-sniffer-maven-plugin` checks the Java 8 and Android API 21 signatures, `japicmp` compares the API against 1.23.2, surefire and failsafe run the 111 test classes, and `.github/workflows/build.yml` runs `mvn compile` then `mvn verify` on JDK 8, 17 and 25 across Ubuntu, Windows and macOS. Every package is `@NullMarked` with `org.jspecify` 1.0.1 annotations, which matters for the next step.

The current Error Prone release runs on JDK 21 or newer, 2.42.0 is the last that runs on the JDK 17 job in `build.yml`, and the JDK 8 job cannot load the plugin at all, so the agent pins 2.42.0 and adds it inside the `multi-release` profile only: `error_prone_core` as an `annotationProcessorPaths` entry on the compiler plugin, `-XDcompilePolicy=simple` and `--should-stop=ifError=FLOW` in `compilerArgs`, and `-Xplugin:ErrorProne` with the checks configured. On JDK 17 and 25 the compiler also needs the `--add-exports` and `--add-opens` flags for `jdk.compiler` that Error Prone's install guide lists, which the agent puts in a `.mvn/jvm.config` file so they apply to every `mvn` invocation and to the IDE. The `java-8` profile is untouched, so the Java 8 build runs no Error Prone and stays as fast as it is.

Because the sources already carry jspecify nullness annotations, the agent adds NullAway as an Error Prone plugin in the same `annotationProcessorPaths` block, with `-Xep:NullAway:ERROR` and `-XepOpt:NullAway:AnnotatedPackages=org.jsoup`, and `-XepOpt:NullAway:JSpecifyMode=true` so the checker reads `@NullMarked` and `@Nullable` the way the code already uses them. The first `mvn -q compile` on JDK 17 then reports what Error Prone and NullAway find across the 105 main classes. The agent fixes the findings that are real (a missed null check, a `MissingOverride`, an `UnusedVariable`), and where a pattern is deliberate in a parser (`FallThrough` in a tokeniser state machine, `ReferenceEquality` on interned strings) it adds `@SuppressWarnings` with a comment naming the reason, or disables the check in `compilerArgs` with the same comment when it fires on every file for the same reason.

Each change is checked against the full matrix in the sandbox: `mvn verify` on JDK 17 with Error Prone active, then `mvn verify` on a JDK 8 toolchain to prove the `java-8` profile still compiles and passes without the plugin, and `mvn verify` again on JDK 21 to be sure the `.mvn/jvm.config` flags are accepted by a newer compiler. `build.yml` does not change, since its matrix already covers the JDKs; the pull request lists what each JDK ran.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Add Error Prone to this Maven build. Read pom.xml, .github/workflows/build.yml, src/main/java/org/jsoup/package-info.java and the layout of src/main/java, src/main/java11, src/test/java and src/test/java11 first. Add error_prone_core to the maven-compiler-plugin annotationProcessorPaths inside the multi-release profile only, with -XDcompilePolicy=simple, --should-stop=ifError=FLOW and -Xplugin:ErrorProne in compilerArgs; leave the java-8 profile untouched. Put the --add-exports and --add-opens flags Error Prone needs for jdk.compiler in .mvn/jvm.config. Add NullAway as an Error Prone plugin with NullAway at ERROR, AnnotatedPackages=org.jsoup and JSpecifyMode on. Run mvn -q compile on JDK 17, fix real findings, and suppress deliberate ones with @SuppressWarnings and a comment naming the reason, or disable a check in compilerArgs with the same comment when it fires everywhere for one reason. Run mvn verify on JDK 17, on a JDK 8 toolchain and on JDK 21 until all pass, then open a pull request listing every check that fired, how many findings each had, and what was fixed versus suppressed.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

The pull request changes `pom.xml` inside the `multi-release` profile, adds `.mvn/jvm.config`, and touches the Java files where a finding was fixed or suppressed. Its description is a table of every Error Prone and NullAway check that fired, with its count, how many of those were fixed and how many suppressed, and the comment text used for each suppression, so a reviewer can read the decisions without opening every file.

It also quotes the `mvn verify` summaries from JDK 17, the JDK 8 toolchain and JDK 21, with the test counts surefire and failsafe reported, and states that `animal-sniffer`, `japicmp` and the multi-release jar packaging ran unchanged, since a compiler plugin that altered the public API or the Java 8 signature would show up there first.

Before merging, a reviewer looks at the suppressed findings for one that should have been a fix, decides whether NullAway should start at `WARN` for a release and move to `ERROR` afterwards, and whether the `build.yml` matrix should name JDK 17 as the job that fails the build on an Error Prone finding, since JDK 8 will never see one.

## Run it on every Maven library without static analysis

A team with several Maven projects sends this body once per repository from its own server, each `POST /o/{org}/sessions` with that repository in `resources` and a `request_id` that is a UUID v5 of the repository's full name, so a retried call returns the run already started. Each run reads its own `pom.xml`: a project with a single default `compile` execution gets the plugin on it directly, one on JDK 8 only gets a pull request that says Error Prone needs JDK 11 and stops there, and a multi-module build gets the configuration in the parent `pluginManagement`.

Once Error Prone is in, an automation on the Project with a `github` trigger on `pull_request.opened` and `pull_request.synchronize` and the prompt "run mvn compile on JDK 17 and, if Error Prone reports a finding in the changed files, comment on the pull request with the check name, the line and the fix" starts one run per push. The trigger adds the pull request after the prompt and fills in nothing else, and only work by an owner, member or collaborator fires it.

## Why run it on Rush?

Adding Error Prone to a mature library is not one line in a pom: the compiler plugin already has five named executions and two JDK-activated profiles, the JDK 8 job cannot load the plugin, newer JDKs need module flags, and the first compile reports findings across a hundred classes that each need a decision. The agent works through all of it in a sandbox where it can install three JDKs, run the full `mvn verify` on each, and record what every check found.

The compile logs from each JDK, the test totals and the table of findings stay with the run, so a reviewer sees why each suppression exists and that the Java 8 build never changed. A team that maintains several Maven libraries runs the same request across all of them at once, each in its own sandbox.

## Frequently asked questions

### Will the JDK 8 build still work?

Yes. Error Prone is added only inside the `multi-release` profile, which activates on JDK 11 and newer, so the `java-8` profile compiles exactly as before and the JDK 8 job in `build.yml` never loads the plugin. The agent runs `mvn verify` on a JDK 8 toolchain in the sandbox to prove it.

### Why NullAway as well?

The sources are already annotated with jspecify's `@NullMarked` and `@Nullable`, so NullAway can check them with `JSpecifyMode` and no new annotations. Error Prone alone does not check nullness; NullAway runs as one of its plugins and turns the annotations the project already wrote into a compile-time check.

### What happens to the findings it cannot fix safely?

A finding that reflects a deliberate pattern, such as fall-through in a state machine, gets `@SuppressWarnings` with a comment naming the reason at the exact site, and a check that fires on every file for the same reason is disabled in `compilerArgs` with the same comment. The pull request's table shows each one, so nothing is silenced quietly.

### Does it change the CI workflow?

No. `build.yml` already runs `mvn compile` and `mvn verify` on JDK 8, 17 and 25, so Error Prone runs on the 17 and 25 jobs through the profile and is skipped on 8. The pull request suggests, but does not make, a change to mark one JDK as the required check.

## More Maven jobs

- [Add JaCoCo Code Coverage to a Maven Project](https://getrush.ai/run/add-jacoco-coverage/maven/)
- [Add the Maven Wrapper to a Maven Project](https://getrush.ai/run/add-maven-wrapper/maven/)
- [Add Mutation Testing to a Maven Project](https://getrush.ai/run/add-mutation-testing/maven/)

## The same job on other stacks

- [Add Error Prone to a Gradle Build](https://getrush.ai/run/add-errorprone/gradle/)

## More jobs like this: Hand off a long task

- [Bundle a VS Code Extension with esbuild](https://getrush.ai/run/add-esbuild-bundling/vscode-extension/)
- [Add ESLint to a Chrome Extension](https://getrush.ai/run/add-eslint/chrome-extension/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
