All jobs

Add an SBOM to a Gradle Build's CI

Yes. An agent adds the CycloneDX plugin to your Gradle build at a version your wrapper supports, generates the SBOM in CI and uploads it with every run, in a PR.

Run this on RushOpens 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 choosing a plugin version, because the CycloneDX Gradle plugin's major lines are tied to Gradle releases. In a project laid out like gothinkster/spring-boot-realworld-example-app, build.gradle applies org.springframework.boot 2.6.3, io.spring.dependency-management 1.0.11.RELEASE, java, the Netflix DGS codegen plugin 5.0.6 and Spotless 6.2.1 with googleJavaFormat(), sets source and target compatibility to Java 11, and declares the application's dependencies directly: Spring Boot starters for web, validation, HATEOAS and security, MyBatis 2.2.2, the DGS GraphQL starter 4.9.21, Flyway, jjwt 0.11.2, Joda-Time, the SQLite JDBC driver and Lombok, with REST Assured 4.5.1 and the Spring test starters for tests. gradle/wrapper/gradle-wrapper.properties points at Gradle 7.4, there is no settings.gradle, and the only workflow, .github/workflows/gradle.yml, sets up Zulu JDK 11 with actions/setup-java@v2, caches ~/.gradle with actions/cache@v2 and runs ./gradlew clean test on every push, every pull request and tags matching v*.

Gradle 7.4 settles the version: the plugin's compatibility table says 3.x needs Gradle 8.4 or newer and 2.x needs 8.0, so the agent applies org.cyclonedx.bom from the 1.x line, 1.10.0, and says in the pull request that moving the wrapper to Gradle 8.4 would allow the current 3.x line and CycloneDX 1.7. It adds the plugin to the plugins block, configures the task to include the runtimeClasspath configuration only, so test-only dependencies such as REST Assured do not appear in the bill of materials for the shipped application, and sets the output to JSON and XML under build/reports/.

In gradle.yml the agent adds a step after the tests, ./gradlew cyclonedxBom, and an actions/upload-artifact step that keeps the two files as a workflow artifact named after the commit, so every CI run of the application has a bill of materials a security team can download. The workflow already runs on v* tags; the agent does not add a release step, because the repository has no releases, and notes in the pull request where an upload to a release would go.

Before opening the pull request it runs ./gradlew cyclonedxBom in its sandbox with a JDK 11, reads build/reports/bom.json, and lists in the pull request how many components the SBOM names and which of them are Spring Boot starters pulled in through the dependency management plugin rather than named in build.gradle. It runs ./gradlew spotlessCheck and ./gradlew test too, since Spotless is applied to every Java file and the plugin change must not disturb the existing build.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "claude",
  "input": "Add a CycloneDX SBOM to this Gradle build and its CI. Read build.gradle, gradle/wrapper/gradle-wrapper.properties, .github/workflows/gradle.yml and README.md first. Pick the org.cyclonedx.bom plugin line that the wrapper's Gradle version supports according to the plugin's compatibility table, and say in the pull request which newer line a Gradle upgrade would allow. Configure the task to include only the runtimeClasspath configuration, output JSON and XML under build/reports/, and add two steps to the existing workflow after the tests: run the task, then upload the files as a workflow artifact. Do not add a release step. Run ./gradlew cyclonedxBom, ./gradlew spotlessCheck and ./gradlew test in your sandbox with JDK 11, count the components in the generated bom.json, and open a pull request with those results. Change no dependency version.",
  "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 (the plugin and its configuration block) and .github/workflows/gradle.yml (two steps). Its description names the plugin version and the compatibility reason, shows the tail of the cyclonedxBom, spotlessCheck and test runs from the sandbox, and gives the component count the agent read from build/reports/bom.json.

Every later CI run produces the SBOM as an artifact beside its test results, for pull requests and tags alike. The dependencies, the Spring Boot version, the Spotless rules and the test command are unchanged; the only new work in CI is one Gradle task and an upload.

Before merging, a reviewer decides whether runtimeClasspath is the right scope for their consumers, how long the artifact should be retained, and whether to schedule the Gradle wrapper upgrade that would allow the 3.x plugin.

Run it on every Gradle project without an SBOM

An organisation that must hand a bill of materials to its security team sends this body once per repository to POST /o/{org}/sessions, each with its own 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 instead of opening a second pull request. Each run reads its own wrapper: a project on Gradle 8.4 or later gets the current plugin line, a multi-project build gets the aggregate task on the root project, and one with a release workflow gets the upload attached to its release step rather than a workflow artifact.

A webhook_url on the key reports each run.completed with the pull request in result, so the person who started the batch sees which builds now produce an SBOM without opening each one.

The use case this job follows, with its automation and trigger: Hand off a long task.

Why run it on Rush?

The plugin is one line; the version is the decision, and it depends on a file most people do not open, the wrapper properties. The agent reads it, matches it against the plugin's own compatibility table, and tells the maintainer what an upgrade would buy. Then it runs the task in its own sandbox with the project's JDK and reads the output, so the pull request says how many components the bill of materials has rather than promising that the task works.

The run keeps every Gradle invocation and its output, and the pull request repeats the parts a reviewer needs. Many builds can be done at once, each with the version its own wrapper allows.

Frequently asked questions

Why not the latest plugin version?

The 3.x line requires Gradle 8.4 and 2.x requires 8.0, per the plugin's compatibility table; this wrapper is on Gradle 7.4, so 1.x is the line that runs. The pull request names the newer line and what a wrapper upgrade would allow, so the choice is visible rather than silent.

Why only runtimeClasspath?

A bill of materials for the shipped application should list what ships. The test configurations pull in REST Assured, the Spring test starters and MyBatis's test starter, which never reach production. Limiting the task to runtimeClasspath keeps those out; a team that also wants a build-time inventory can add a second task.

Where does the SBOM go?

To build/reports/ locally and to a workflow artifact in CI, one per run. The repository has no releases, so the agent attaches nothing to one; the pull request notes where an upload step would go in a release workflow.

Does it change any dependency?

No. The plugin reads the resolved dependency graph and writes it out. Versions, the Spring Boot BOM and the Spotless rules are untouched, and ./gradlew test is run in the sandbox to show the build is as it was.

More Gradle jobs

The same job on other stacks

More jobs like this: Hand off a long task

Keep reading