Adding JaCoCo Coverage to GitHub Actions
Produce a JaCoCo XML report in CI and comment per-PR coverage for your JVM project.
JaCoCo is the standard coverage tool for the JVM. In CI you run the jacocoReport task (Gradle) or jacoco:report goal (Maven), which writes an XML report. A community action can then turn that XML into a PR comment, or you can hand it to Codecov.
What you need
- JaCoCo applied in build.gradle or the jacoco-maven-plugin in pom.xml.
- A test task that runs before the report task.
- The path to the generated jacoco.xml (build/reports/jacoco/test/jacocoTestReport.xml).
The workflow
Run tests plus the JaCoCo report, then comment coverage.
.github/workflows/ci.yml
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 21
- run: ./gradlew test jacocoTestReport
- uses: madrapps/jacoco-report@v1.7
with:
paths: build/reports/jacoco/test/jacocoTestReport.xml
token: ${{ secrets.GITHUB_TOKEN }}
min-coverage-overall: 80Common gotchas
- jacocoTestReport does not run tests; you must run test first or the report is empty.
- XML reporting is off by default in Gradle - enable xml.required = true.
- min-coverage thresholds fail the job, so set them deliberately to avoid blocking everyone.
Key takeaways
- Run tests before jacocoTestReport, and enable XML output.
- madrapps/jacoco-report turns jacoco.xml into a PR comment.
- Coverage thresholds become a hard gate, so tune them.
Related guides
Generating lcov Coverage Reports in GitHub ActionsProduce and publish an lcov coverage report in GitHub Actions, merge per-shard reports, and feed it to Codeco…
Adding .NET Coverage with Coverlet to GitHub ActionsCollect .NET test coverage with Coverlet in GitHub Actions, emit Cobertura XML, and upload it to Codecov or r…
Adding Codecov to GitHub ActionsUpload code coverage to Codecov from a GitHub Actions workflow: generate an lcov/Cobertura report, add the co…