# Add Dependency Verification to a Gradle Build

Yes. An agent bootstraps gradle/verification-metadata.xml with checksums for every dependency and plugin, makes CI fail on a changed artifact, and opens a PR.

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

## What the agent does

The agent reads what the build resolves before it writes a single checksum. In a project laid out like spring-projects/spring-petclinic, `build.gradle` applies `java`, `checkstyle`, `org.springframework.boot` at `4.1.0`, `io.spring.dependency-management` at `1.1.7`, `org.graalvm.buildtools.native` at `1.1.2`, `org.cyclonedx.bom` at `3.2.4`, `io.spring.javaformat` at `0.0.47` and `io.spring.nohttp` at `0.0.11`, sets a Java 17 toolchain, and declares its dependencies without versions except for the webjars and checkstyle artifacts, so Spring Boot's BOM decides most of what gets downloaded. `settings.gradle` is one line, `rootProject.name`, with no toolchain resolver plugin, so no JDK is downloaded. `gradle/wrapper/gradle-wrapper.properties` pins Gradle `9.5.1`, and `gradle/` holds nothing else: there is no `verification-metadata.xml`, so every jar, POM and module file arrives unchecked. `.github/workflows/gradle-build.yml` sets up JDK 17 with `cache: maven`, which does nothing for this build, runs `gradle/actions/setup-gradle@v4` and `./gradlew build`. A `pom.xml` and `maven-build.yml` run the same project under Maven and are left alone.

The bootstrap is `./gradlew --write-verification-metadata sha256 build`. Running it with `build` rather than `help` resolves the test and runtime configurations, the checkstyle classpath and the plugin classpaths, so the generated `gradle/verification-metadata.xml` covers the Spring Boot plugin, the dependency-management plugin, the GraalVM and CycloneDX plugins, every library the BOM selects and the webjars, each as a `<component>` with a `<sha256>` for its jar and its metadata files. The agent reads the file top to bottom before trusting it, because bootstrapping records whatever Maven Central served at that moment: it spot-checks a handful of entries against the checksums published on the repository, confirms there are no `-SNAPSHOT` components, and leaves `<verify-metadata>` at `true` so POM and module files are checked as well as jars. `<verify-signatures>` stays `false` in this pull request; the `pgp,sha256` mode with `--export-keys` and a `gradle/verification-keyring.keys` file is described as the next step rather than mixed in.

The file is only useful if it stays complete, so the agent closes the two ways it drifts. For IDE and sources jars it adds a `<trusted-artifacts>` block with a `<trust>` regex for `-sources.jar` and `-javadoc.jar` files, which Gradle otherwise fails on the first time an IDE asks for them. For dependency updates it adds a short section to `README.md`: after changing a version, run the same `--write-verification-metadata sha256` command and commit the diff, and a mismatch means the artifact changed, not that the file is stale. The CI workflow gets a second step after `./gradlew build` that reruns the bootstrap and then `git diff --exit-code gradle/verification-metadata.xml`, so a pull request that bumps a dependency without regenerating the file fails with the missing entries in the diff, and the `cache: maven` line is corrected to `gradle` while the file is open.

The agent proves both directions in its sandbox. It runs `./gradlew build` with the metadata in place and confirms the build passes in the default `strict` mode; then it edits one `<sha256>` value, runs the build again, and keeps the failure output naming the artifact and the expected and actual checksums; then it deletes a component, runs with `--dependency-verification lenient` to see the warning form, and restores the file. It runs `./gradlew --write-verification-metadata sha256 --dry-run build` once more to confirm the `verification-metadata.dryrun.xml` it writes matches the committed file, and opens the pull request.

## Start it with one API call

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

```json
{
  "agent": "claude",
  "input": "Add Gradle dependency verification to this project and open a pull request. Read build.gradle, settings.gradle, gradle/wrapper/gradle-wrapper.properties, the contents of gradle/, .gitignore and every workflow under .github/workflows first. Run ./gradlew --write-verification-metadata sha256 build so test, runtime, checkstyle and plugin classpaths are all resolved, and commit gradle/verification-metadata.xml with verify-metadata true and verify-signatures false. Read the generated file, spot-check several checksums against the repository's published values, and confirm no snapshot component is listed. Add a trusted-artifacts rule for sources and javadoc jars. In the Gradle workflow, fix the setup-java cache to gradle and add a step that reruns the bootstrap and fails on git diff --exit-code for the metadata file. Add a README section on regenerating the file after a dependency change. In the sandbox, prove a tampered checksum fails the build and a lenient run only warns, restore the file, run ./gradlew build and the dry-run bootstrap, then open a pull request that quotes the failure output and lists the plugin and library counts in the metadata.",
  "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 adds `gradle/verification-metadata.xml`, changes `.github/workflows/gradle-build.yml` and `README.md`, and touches nothing under `src`. Its description says how many components the file holds, split into plugins and libraries, quotes the strict-mode failure Gradle printed for the tampered checksum with the artifact name and both hashes, and quotes the lenient-mode warning for the removed component, so a reviewer knows what each mode will look like the first time it fires.

It is clear about the file's trust boundary: the checksums were recorded from what the repository served on the day of the run, a handful were checked by hand against published values, and signature verification is a separate change that needs a keyring and key review. The `trusted-artifacts` entry is explained as the one place verification is deliberately relaxed and why.

Before merging, a reviewer reads the `<configuration>` block, decides whether sources and javadoc jars should really be trusted or verified too, and agrees on who regenerates the file when Dependabot or a person bumps a version, since the new CI step will fail any such pull request until they do.

## Run it on every dependency update pull request

An automation on the Project with a `github` trigger on `pull_request.opened` and the prompt "if this pull request changes a dependency or plugin version in build.gradle, run ./gradlew --write-verification-metadata sha256 build, commit the metadata diff to the pull request's branch, and comment with the components added and removed" starts one run per opened pull request. The trigger adds the pull request after the prompt and fills in nothing else; a pull request that touches only source files gets a run that reads the diff and stops.

A platform team with many Gradle services 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 build: a multi-project build gets one file at the root covering every subproject, and one that already has a metadata file gets it regenerated and its missing `trusted-artifacts` rule added.

## Why run it on Rush?

Dependency verification is easy to switch on and easy to get subtly wrong: a bootstrap run against `help` that misses the test classpath, a file that nobody regenerates so the first dependency bump breaks CI with no explanation, a mismatch that gets fixed by deleting the entry instead of asking why the artifact changed. The agent resolves every configuration, reads what it recorded, writes down the regeneration rule where the next person will look, and shows what a failure looks like before anyone meets one.

The bootstrap output, the tampered-checksum failure, the lenient warning and the clean build all stay with the run, so a reviewer sees the mechanism work rather than reading that it should. A team with many Gradle builds sends the same request to each and gets one pull request per repository, each with its own metadata and proof.

## Frequently asked questions

### Does this cover plugins as well as libraries?

Yes. Gradle verifies plugin artifacts resolved from the plugin portal and Maven Central the same way, so the Spring Boot, dependency-management, GraalVM, CycloneDX, javaformat and nohttp plugins all have entries. The Gradle distribution itself is downloaded by the wrapper and is outside this file; `gradle-wrapper.properties` has its own `distributionSha256Sum` field for that.

### What happens when someone bumps a version?

The build fails in strict mode with the missing component named, and the CI diff step fails too. The fix is the command in the README: rerun `./gradlew --write-verification-metadata sha256 build`, which keeps existing entries and adds the new ones, and commit the file. A checksum that changed for an existing version is different and should be investigated, not overwritten.

### Why not verify PGP signatures from the start?

Signature verification needs a keyring and a list of trusted keys, and each key has to be confirmed against the project that owns it, which is review work rather than a mechanical step. Checksums alone already catch a swapped artifact. The pull request names `--write-verification-metadata pgp,sha256 --export-keys` and the `gradle/verification-keyring.keys` file as the follow-up.

### Does the Maven build change?

No. `pom.xml` and the Maven workflow are left as they are; this file only affects Gradle. A team that wants the same guarantee on the Maven side would look at Maven's own checksum policy and artifact signing, which is a separate change.

## More Gradle jobs

- [Add a Dockerfile to a Gradle Spring Boot App](https://getrush.ai/run/add-dockerfile/gradle/)
- [Add Error Prone to a Gradle Build](https://getrush.ai/run/add-errorprone/gradle/)
- [Add JaCoCo Coverage to a Gradle Spring Boot Project](https://getrush.ai/run/add-jacoco-coverage/gradle/)

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

- [Add a GitHub Pages Deploy Workflow to an Eleventy Site](https://getrush.ai/run/add-deploy-workflow/eleventy/)
- [Deploy Firebase Functions from GitHub Actions](https://getrush.ai/run/add-deploy-workflow/firebase-functions/)
- [Add a GitHub Pages Deploy Workflow to a Hugo Site](https://getrush.ai/run/add-deploy-workflow/hugo/)

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