SupercovBlog

Guide

JaCoCo aggregate report for multi-module Maven and Gradle builds

Eight setups on a two-module project with JaCoCo 0.8.16, Maven and Gradle: which one reports code covered from another module.

One JaCoCo report across every module. Two small brushed-aluminum trays of white tiles, each with gaps, behind a larger tray where every tile is in place and one is violet.

A JaCoCo report per module counts only that module’s own tests. To see code in one module covered by tests in another, add a separate module that depends on all the others and runs report-aggregate in Maven, or apply jacoco-report-aggregation in Gradle. An aggregate goal in the parent pom writes an empty report.

A diagram of two modules: core's tests write core/jacoco.exec with Pricing at 1 of 8 lines, api's tests write api/jacoco.exec, which also ran Pricing.total. Both exec files feed report-aggregate, which shows Pricing 6 of 8 and Checkout 1 of 2.
Per-module reports read one exec file; the aggregate reads every dependency's.

Aggregate report setups at a glance

SetupWhat the report showed
Per-module report onlyPricing 1 of 8 lines, though api’s tests ran 6
Maven: coverage module with report-aggregate, depends on every modulePricing 6/8, Checkout 1/2
Maven: coverage module missing the api dependencyPricing 1/8; api left out
Maven: report-aggregate in the parent pomEmpty report
Maven: mvn test instead of mvn verifyNo aggregate report
Gradle: jacoco-report-aggregation in a coverage project with a JacocoCoverageReport registeredPricing 6/8, Checkout 1/2
Gradle: the same without the reporting blockTask 'testCodeCoverageReport' not found
Gradle: plugin applied in api itselfPricing 6/8, Checkout 1/2

We ran every setup with JaCoCo 0.8.16, Maven 3.9.16 and Gradle 9.7.1 on JDK 26. The project has two modules: core holds shop.core.Pricing with one test for its format method, and api holds Checkout, whose two tests call Pricing.total through Checkout.quote.

Why the per-module report misses lines

<execution><goals><goal>prepare-agent</goal></goals></execution>
<execution><id>report</id><phase>test</phase><goals><goal>report</goal></goals></execution>

With these executions in the parent pom, each module writes target/site/jacoco. core’s report showed Pricing at 1 of 8 lines: only format. The api tests did run total, and their jacoco.exec recorded it, but that file sits in api/target, and api’s own report covers only api’s classes.

Maven: a separate module for report-aggregate

<project>
  <parent>…shop-parent…</parent>
  <artifactId>coverage</artifactId>
  <packaging>pom</packaging>
  <dependencies>
    <dependency><groupId>shop</groupId><artifactId>core</artifactId><version>1.0.0</version></dependency>
    <dependency><groupId>shop</groupId><artifactId>api</artifactId><version>1.0.0</version></dependency>
  </dependencies>
  <build><plugins><plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <executions>
      <execution>
        <id>aggregate</id><phase>verify</phase>
        <goals><goal>report-aggregate</goal></goals>
      </execution>
    </executions>
  </plugin></plugins></build>
</project>

Add <module>coverage</module> to the parent and run mvn verify. The report lands in coverage/target/site/jacoco-aggregate, with Pricing at 6 of 8 lines and Checkout at 1 of 2. report-aggregate reads the execution data and classes of the module’s dependencies, so every module has to be a dependency; with core alone, Pricing dropped back to 1/8 and Checkout was gone.

A grid of seven setups against two classes, Pricing and Checkout. Core's own report: Pricing 1/8. A coverage module depending on core and api: both, Pricing 6/8. Depending on core only: Pricing 1/8. Report-aggregate in the parent: empty. mvn test: no report. A Gradle coverage project: both, Pricing 6/8. Gradle without the reporting block: task not found.
What each JaCoCo report contained, measured with JaCoCo 0.8.16.

Why the Maven aggregate report is empty

What we triedWhat happened
report-aggregate in the parent pomtarget/site/jacoco-aggregate with no classes
The same execution, inherited by apiPricing 6/8, but no Checkout
mvn testNo aggregate report: it is bound to verify
coverage without the api dependencyapi’s tests and classes left out

The parent builds before its modules and depends on none of them, so its aggregate report had nothing to read. The goal also leaves out the module it runs in: inherited by api, it reported core’s Pricing and not api’s own Checkout. A module of its own avoids both.

Gradle: jacoco-report-aggregation

// coverage/build.gradle.kts
plugins {
    base
    `jacoco-report-aggregation`
}

repositories { mavenCentral() }

dependencies {
    jacocoAggregation(project(":core"))
    jacocoAggregation(project(":api"))
}

reporting {
    reports {
        register<JacocoCoverageReport>("testCodeCoverageReport") {
            testSuiteName = "test"
        }
    }
}

gradle testCodeCoverageReport ran both projects’ tests and wrote coverage/build/reports/jacoco/testCodeCoverageReport with Pricing 6/8 and Checkout 1/2. Without the reporting block the task does not exist, and Gradle stops with “Task ‘testCodeCoverageReport’ not found”. Listing only :api was enough here, because api depends on core; listing only :core left api’s tests out.

In a project that already applies java, the plugin registers the task by itself. Applied in api, gradle testCodeCoverageReport aggregated api and core with no reporting block. gradle test alone writes no aggregate report.

What Supercov adds

npx supercov -- mvn test
npx supercov runs latest gaps

Supercov measured both modules in one run, with no aggregation module: the 3 tests across core and api, Pricing.total covered by the api tests, and one line left, the throw for a quantity of zero. It also showed that member && sum >= 10_000 was never run with member false, an MC/DC gap the line counts hide. See JaCoCo report not generated when there is no report at all, and Java code coverage tools for the alternatives.

More coverage guides