# Add Error Prone to a Gradle Build

Yes. An agent adds Error Prone to your Gradle Java build at a version your JDK runs, excludes generated code, handles each finding with a reason, and opens a PR.

[Run this on Rush](https://cloud.getrush.ai/run/add-errorprone/gradle/). 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 adding a compiler plugin to it. In an app laid out like gothinkster/spring-boot-realworld-example-app, `build.gradle` applies `org.springframework.boot` 2.6.3, `io.spring.dependency-management`, `java`, `com.netflix.dgs.codegen` 5.0.6 and `com.diffplug.spotless` 6.2.1 with `googleJavaFormat()`, sets `sourceCompatibility` and `targetCompatibility` to `11`, and makes `compileOnly` extend `annotationProcessor` for Lombok, which is on both. The `generateJava` task writes the GraphQL types from `src/main/resources/schema` into `build/generated`, and Spotless already excludes `build/generated/**` and `build/generated-examples/**`. `gradle/wrapper/gradle-wrapper.properties` pins Gradle 7.4, there is no `settings.gradle`, and `.github/workflows/gradle.yml` runs `./gradlew clean test` on Zulu JDK 11. The 116 Java files under `src/main/java/io/spring` split into `api`, `core`, `application`, `infrastructure` and `graphql` packages, with MyBatis mappers under `infrastructure/mybatis`. No static analysis runs beyond the compiler's own warnings.

The version choice follows from that JDK. Error Prone 2.32.0 raised the JDK it runs on to 17, so on a build that compiles and tests on JDK 11 the agent pins `com.google.errorprone:error_prone_core:2.31.0`, the last release that runs there, and applies `net.ltgt.errorprone` at its current 5.x release, which needs Gradle 7.1 and a JDK 11 toolchain, both of which this build has. It records the alternative in the pull request: a Gradle toolchain on JDK 17 with `options.release = 11` would allow the current Error Prone while still producing Java 11 bytecode, and is the route to take when the CI JDK moves. The dependency goes into the `errorprone` configuration the plugin creates, as a fixed version and never `latest.release`, because a new Error Prone release adds checks and would change the build's result on its own.

Configuration goes on every `JavaCompile` task in `build.gradle`: `options.errorprone.disableWarningsInGeneratedCode = true` so Lombok's generated methods do not report, `excludedPaths = '.*/build/generated/.*'` so the DGS codegen output under `build/generated` is skipped the way Spotless already skips it, and `compileTestJava` keeps Error Prone enabled but with `compilingTestOnlyCode = true`, which relaxes the checks that do not apply to tests. The agent then runs `./gradlew clean compileJava compileTestJava` and reads the output. Each finding is handled one of three ways and the pull request says which: a real bug is fixed in the source; a pattern the project uses on purpose, such as MyBatis mapper interfaces whose unused parameters are bound by name, is disabled by check name with `options.errorprone.disable(...)` and a comment giving the reason; and a one-off is suppressed at the site with `@SuppressWarnings` naming the check. Nothing is promoted to error in this first pass, so the build stays green while the warnings are visible.

The last step keeps the warnings from coming back silently. `gradle.yml` gets `./gradlew compileJava compileTestJava --warning-mode all` before the tests so Error Prone's output appears in the Actions log, and the pull request proposes `options.errorprone.error(...)` for the checks that found nothing, which turns a future regression into a compile failure; it is left as a proposal because deciding which checks become errors is the team's call. The agent runs `./gradlew spotlessCheck` and `./gradlew test` after its changes, since `googleJavaFormat()` governs every Java file it touched.

## Start it with one API call

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

```json
{
  "agent": "claude",
  "input": "Add Error Prone to this Gradle Java build. Read build.gradle, gradle/wrapper/gradle-wrapper.properties, .github/workflows/gradle.yml and the layout of src/main/java first, and check which JDK the build compiles on. Apply the net.ltgt.errorprone plugin at its current release and add com.google.errorprone:error_prone_core to the errorprone configuration at a fixed version that runs on that JDK, explaining in the pull request the alternative of a JDK 17 toolchain with options.release. Configure every JavaCompile task to disable warnings in generated code, exclude the DGS codegen output under build/generated, and mark the test compile as test-only code. Run compileJava and compileTestJava, then handle every finding: fix real bugs, disable a check with a commented reason when the project relies on the pattern, and suppress one-offs at the site naming the check. Promote nothing to error yet but list candidate checks. Add the compile step with warnings to the CI workflow. Run spotlessCheck and test, and open a pull request with a table of findings and what was done with each.",
  "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 `build.gradle`, `.github/workflows/gradle.yml` and whichever Java files under `src/main/java/io/spring` had a finding worth fixing or suppressing. Its description quotes the Error Prone output from the first compile, a table with one row per finding naming the check, the file and the action taken, the `spotlessCheck` and `test` results after the changes, and the list of checks that reported nothing and could become errors.

A reviewer reads the fixes as ordinary bug fixes, checks each `disable(...)` reason against how the project uses the pattern, and decides which of the proposed checks to promote with `error(...)`. They also read the JDK note and decide when to move the build to a toolchain so the Error Prone version can advance.

Spotless, the DGS codegen task, the Spring Boot plugin and the dependency versions are untouched; the only new dependency is in the `errorprone` configuration, which never reaches the runtime classpath.

## Run it on every Java repository without static analysis

A team with many Gradle services can send this body once per repository from a short script on its own server: list what the GitHub App reaches with `GET /o/{org}/github`, keep the repositories whose default branch has a `build.gradle` or `build.gradle.kts` without `errorprone` in it, and give each request a `request_id` that is a UUID v5 of the repository's full name so a rerun returns the runs it already started. Each run opens one pull request fitted to that build's JDK and plugins, and the key's `webhook_url` receives `run.completed` for each.

After it is merged, an automation on the Project with a `github` trigger on `pull_request.opened` and `pull_request.synchronize` can run read-only with a prompt that compiles the branch and comments when a new Error Prone warning appears or a new `@SuppressWarnings` lacks a reason. The trigger adds the event after the prompt; it fills in no placeholder.

## Why run it on Rush?

Adding Error Prone is a version decision before it is a configuration: the current release will not run on a JDK 11 build, a dynamic version makes the build change on its own, Lombok and code generators produce exactly the patterns the checks flag, and the first run on a real codebase produces a list that someone has to work through. The agent reads the build's JDK and plugins, pins what runs there, excludes what is generated, and compiles in its sandbox so every finding in the pull request is one it saw and handled, with the compiler output kept in the run's record.

The result is a build that reports, not yet one that fails, which is the state a team can review and tighten one check at a time.

## Frequently asked questions

### Why not the newest Error Prone?

Error Prone 2.32.0 and later need JDK 17 to run, and this build compiles and tests on JDK 11 in `gradle.yml`. 2.31.0 is the last release that runs on 11, so it is pinned. Moving to a JDK 17 toolchain with `options.release = 11` keeps Java 11 bytecode and allows the current release; the pull request shows that configuration.

### Will it flag Lombok and the GraphQL codegen?

`disableWarningsInGeneratedCode` silences warnings in Lombok's generated members, and `excludedPaths` skips `build/generated`, where the DGS plugin writes the schema types, the same directory Spotless already excludes. Hand-written code is the only thing that reports.

### Does the build fail on a warning?

Not in this pull request. Every check stays at its default severity, the real findings are fixed or suppressed with a reason, and the CI step makes the output visible. The checks that reported nothing are listed as candidates for `options.errorprone.error(...)`, which the team enables when it wants a regression to break the build.

### Does Error Prone slow the build?

It runs inside `javac`, so `compileJava` takes longer while the tests are unchanged. On JDK 16 and later the plugin forks the compiler to add the `--add-exports` flags it needs; on JDK 11 no fork is required. The pull request quotes the compile time before and after from the Gradle output.

## More Gradle jobs

- [Add JaCoCo Coverage to a Gradle Spring Boot Project](https://getrush.ai/run/add-jacoco-coverage/gradle/)
- [Add OWASP Dependency-Check to a Gradle Build](https://getrush.ai/run/add-owasp-dependency-check/gradle/)
- [Add Renovate to a Gradle and Maven Project](https://getrush.ai/run/add-renovate/gradle/)

## The same job on other stacks

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

## 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/)
