Skip to content
Latchkey

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: 80

Common 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

Run this faster and cheaper on Latchkey managed runners. Start free →