# The JaCoCo Report Aggregation Plugin

version 7.6.6-20260704033542+0000

The JaCoCo Report Aggregation plugin (plugin id: `jacoco-report-aggregation`) provides the ability to aggregate the results of multiple JaCoCo code coverage reports (potentially spanning multiple Gradle projects) into a single HTML report. The binary data backing the coverage reports are produced by Test task invocations; see more at the JaCoCo Plugin chapter.

## Usage

To use the JaCoCo Report Aggregation plugin, include the following in your build script:

    plugins {
        id 'jacoco-report-aggregation'
    }

    plugins {
        id("jacoco-report-aggregation")
    }

Note that this plugin takes no action unless applied in concert with the JVM Test Suite Plugin. The Java Plugin automatically applies the JVM Test Suite Plugin.

There are now two ways to collect code coverage results across multiple subprojects:

1. From the distribution’s project, such as an application or WAR subproject → distribution sample

2. Using a standalone project to specify subprojects → standalone sample

Example 2 could also be used to aggregate results via the root project.

| The JaCoCo Report Aggregation plugin does not currently work with the `com.android.application` plugin.

## Tasks

When the project also applies the `jvm-test-suite` plugin, the following tasks are added for each test suite:

`testSuiteCodeCoverageReport` — JacocoReport

  Depends on: Artifacts of variants matching the below attributes

  Collects variants of direct and transitive project dependencies via the `jacocoAggregation` configuration. The following Attributes will be matched:

        - org.gradle.category              = verification   (1)
        - org.gradle.testsuite.type        = unit-test      (2)
        - org.gradle.verificationtype      = jacoco-results   (3)

1 | Category attribute; value is fixed.
2 | TestSuiteType attribute; value is derived from JvmTestSuite#getTestType().
3 | VerificationType attribute; value is fixed.

More information about the variants produced by test execution with JaCoCo are available in the Outgoing Variants section of the JaCoCo Plugin documentation.

## Reports

| By default, Gradle stops executing tasks when any task fails — including test failures. To ensure that your builds always generate aggregation reports, specify the `--continue` option in your Gradle command. For more information, see continuing the build when a failure occurs.

### Automatic report creation

When the project also applies the `jvm-test-suite` plugin, the following reporting objects are added for each test suite:

`testSuiteCodeCoverageReport` — JacocoCoverageReport

  Creates a container to parameterize the TestSuiteType value.

### Manual report creation

When the project does not apply the `jvm-test-suite` plugin, you must manually register one or more reports:

Example 1. Create a reporting container
build.gradle

    reporting {
        reports {
            testCodeCoverageReport(JacocoCoverageReport) { (1)
                testType = TestSuiteType.UNIT_TEST
            }
        }
    }

build.gradle.kts

    reporting {
        reports {
            val testCodeCoverageReport by creating(JacocoCoverageReport::class) { (1)
                testType.set(TestSuiteType.UNIT_TEST)
            }
        }
    }

1 | Creates a report named `testCodeCoverageReport` of type `JacocoCoverageReport`. For convenience, sets `TestType` using a constant value from the TestSuiteType class. Any String value is acceptable.

Report creation automatically creates backing tasks to aggregate coverage results for the given test suite type value.

## Dependency management

The JaCoCo Report Aggregation plugin adds the following dependency configurations:

Table 1. JaCoCo Report Aggregation plugin - dependency configurations
Name | Meaning
--- | ---
`jacocoAggregation` | The configuration used to declare all project dependencies having code coverage data to be aggregated.
`allCodeCoverageReportSourceDirectories` | Consumes the project dependencies from the `jacocoAggregation` configuration to collect all `main-source` variants. Prevents external libraries' classes from being included in the aggregated results.
`allCodeCoverageReportClassDirectories` | Consumes the project dependencies from the `jacocoAggregation` configuration to collect all classes directories. Prevents external libraries' classes from being included in the aggregated results.
`testReportNameExecutionData` | Consumes the project dependencies from the `jacocoAggregation` configuration using variant-aware matching to find the appropriate test suite type.

It is not necessary to explicitly add dependencies to the `jacocoAggregation` configuration if the project also applies the `jvm-test-suite` plugin.

Note the `testReportNameExecutionData` and `allCodeCoverageReport*Directories` configurations may display resolution errors for external dependencies, as these do not expose code coverage data. This is expected behavior and does not affect the outcome of the build or code coverage aggregation process.