The JaCoCo Report Aggregation Plugin
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:
-
From the distribution’s project, such as an application or WAR subproject → distribution sample
-
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 |
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:
reporting {
reports {
val testCodeCoverageReport by creating(JacocoCoverageReport::class) { (1)
testType = TestSuiteType.UNIT_TEST
}
}
}
reporting {
reports {
testCodeCoverageReport(JacocoCoverageReport) { (1)
testType = 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:
Name | Meaning |
---|---|
|
The configuration used to declare all project dependencies having code coverage data to be aggregated. |
|
Consumes the project dependencies from the |
It is not necessary to explicitly add dependencies to the jacocoAggregation
configuration if the project also applies the jvm-test-suite
plugin.