All jobs

Add OWASP Dependency-Check to a Gradle Build

Yes. An agent adds the OWASP dependency-check plugin to your Gradle build with a CVSS threshold, a suppression file and a CI job that keeps the report, 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 and the workflow before it adds a plugin that downloads a vulnerability database, because where the data is cached decides whether the check takes a minute or an hour. In a service laid out like gothinkster/spring-boot-realworld-example-app, build.gradle applies Spring Boot 2.6.3, the dependency-management plugin, java, the Netflix DGS codegen plugin 5.0.6 and Spotless 6.2.1 with googleJavaFormat, targets Java 11, and declares its dependencies with explicit versions where Spring Boot's BOM does not cover them: mybatis-spring-boot-starter 2.2.2, graphql-dgs-spring-boot-starter 4.9.21, jjwt 0.11.2 in three artifacts, joda-time 2.10.13, sqlite-jdbc 3.36.0.3, Lombok, and REST Assured 4.5.1 for tests. The wrapper in gradle/wrapper/gradle-wrapper.properties is Gradle 7.4, there is no settings.gradle, test runs on the JUnit platform, and clean deletes the SQLite dev.db. .github/workflows/gradle.yml is one build job on every branch and v* tag: actions/checkout@v2, setup-java@v2 with Zulu 11, an actions/cache@v2 over ~/.gradle/caches and ~/.gradle/wrapper keyed on the Gradle files, and ./gradlew clean test. src/main/resources/db/migration/ holds one Flyway script and application.properties holds the JWT secret in plain text, which is a different problem the pull request notes without touching.

The agent adds org.owasp.dependencycheck, current release 13.0.0, to the plugins block and a dependencyCheck block under it. failBuildOnCVSS is set to the threshold you choose for a first rollout, formats lists HTML for people and SARIF for GitHub's code scanning, suppressionFile points at a new dependency-check-suppressions.xml that starts empty but valid, with a comment showing the shape of a suppression with a notes and an expiry, and scanConfigurations is limited to runtimeClasspath so a test-only library such as REST Assured is reported but does not fail the build. The plugin's NVD download needs an API key to run at a usable rate, so nvd.apiKey reads System.getenv("NVD_API_KEY") and the block tolerates its absence for a local run. Because Spotless formats only Java, the Groovy change needs no formatting step, but the agent runs spotlessCheck anyway since build.gradle moved.

gradle.yml gains a second job, dependency-check, that reuses the checkout and JDK steps, adds an actions/cache entry over ~/.gradle/dependency-check-data keyed on the week so the NVD database is downloaded once and updated incrementally, runs ./gradlew dependencyCheckAnalyze with NVD_API_KEY from the repository's secrets, uploads build/reports/dependency-check-report.html as an artifact on every outcome, and uploads the SARIF file through github/codeql-action/upload-sarif with security-events: write on that job alone, so findings appear under the Security tab with their CVE ids and the dependency path. The existing build job is untouched, and the new job does not block it, so a database outage never stops the tests.

To check it, the agent runs ./gradlew dependencyCheckAnalyze in its sandbox with the database download it can get, reads the report, and lists in the pull request every dependency flagged at or above the threshold with its CVE ids and the build.gradle line it comes from, without suppressing any of them: on a build that pins versions from early 2022, the first report is expected to be long, and the decision to upgrade or to suppress with a reason and an expiry is a reviewer's. If the download cannot finish in the sandbox, the pull request says so and the first full report comes from the workflow's run. It runs ./gradlew clean test and spotlessCheck to show the build and the format check still pass with the plugin applied.

Start it with one API call

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

{
  "agent": "claude",
  "input": "Add OWASP Dependency-Check to this Gradle build. Read build.gradle, gradle/wrapper/gradle-wrapper.properties, .github/workflows/gradle.yml and README.md first. Apply the org.owasp.dependencycheck plugin and configure it with a failBuildOnCVSS threshold, HTML and SARIF formats, a suppression file that starts empty with a commented example carrying notes and an expiry, scanConfigurations limited to runtimeClasspath, and an NVD API key read from the NVD_API_KEY environment variable that is tolerated when absent. Add a dependency-check job to the workflow that reuses the JDK setup, caches the dependency-check data directory, runs dependencyCheckAnalyze with the key from secrets, uploads the HTML report as an artifact on every outcome and the SARIF to code scanning with security-events write on that job only, and does not block the existing build job. Run the analysis in your sandbox as far as the database download allows and list every finding at or above the threshold with its CVE ids and build.gradle line without suppressing any, run clean test and spotlessCheck, and open a pull request with the output.",
  "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 and .github/workflows/gradle.yml and adds dependency-check-suppressions.xml. Its description lists the findings from the sandbox analysis grouped by dependency, each with its CVE ids and the build.gradle line, the clean test and spotlessCheck output, and a plain statement of whether the NVD download completed in the sandbox or the first full report will come from the workflow.

The Java CI workflow runs on the pull request with the unchanged build job and the new dependency-check job beside it, the HTML report attached to the run as an artifact, and the SARIF findings on the pull request's Security tab. The run's record keeps the plugin's own output, including the database update it performed.

Before merging, a reviewer picks the threshold the team will hold itself to, decides for each finding between an upgrade, a suppression with a reason and an expiry, or a change to the threshold, and decides whether the job should block merges once the first findings are handled. The dependencies, the tests and the Flyway migration are unchanged.

Run it on every Gradle service without a dependency scan

A team with several Gradle services 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 rather than opening a second pull request. Each run reads its own build: a multi-project build gets the plugin in the root with dependencyCheckAggregate, a Kotlin DSL build gets the same block in build.gradle.kts, and one that already runs on a GitHub-hosted Java matrix gets the job added to that workflow.

Once the job is merged it runs on every push, so no further run is needed to keep the report current. A webhook_url on the key reports each run.completed with the pull request in result, and a run.failed names a build the plugin could not be applied to, for instance one on a Gradle version the plugin no longer supports, which is worth a separate upgrade.

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, but a useful first rollout is a dozen decisions: which configurations to scan, where to cache the database, how to get an API key into CI, what to do with the SARIF, and above all what to do with a first report that is long because the versions are old. The agent reads the build and the workflow, wires every piece in its own sandbox, and brings back the findings as a list to decide on rather than a wall to suppress.

The analysis output, the test run and the format check stay with the run and are pasted into the pull request, so the review is a list of CVEs with their lines rather than a plugin to try out. Several services can get the same scan at once, each with its own report.

Frequently asked questions

Will the first run fail the build?

If any runtime dependency has a vulnerability at or above the threshold, yes, and on a build that pins versions from early 2022 that is likely. That is why the new job does not block the existing build job and why the agent lists the findings instead of suppressing them: the first pull request is where the team decides what to upgrade, what to suppress with a reason and an expiry, and where to set the bar.

Why does it need an NVD API key?

Because the plugin downloads and updates the National Vulnerability Database, and without a key the download is throttled hard enough to make a CI job impractical. The key is free, lives in the repository's secrets as NVD_API_KEY, and the cache over the data directory means each run updates the database rather than fetching it again.

Are test dependencies scanned?

They are reported in the HTML file but do not fail the build, because scanConfigurations is limited to runtimeClasspath. REST Assured and the Spring test starters never ship, so a vulnerability in them is worth knowing but not worth blocking a release; widening the list is one line.

Does this replace Dependabot or Renovate?

No. Those open upgrade pull requests; this scans what the build actually resolves, including transitive dependencies the BOM pulls in, and fails when something crosses the threshold. The two work together: the scan finds the problem, the update bot proposes the fix, and the suppression file records what was accepted and until when.

More Gradle jobs

The same job on other stacks

More jobs like this: Hand off a long task

Keep reading