NOTE: You can open this sample in an link:{userManualPath}/gradle_ides.html#gradle_ides[IDE that supports Gradle].

This sample shows how to aggregate code coverage across multiple Java subprojects using link:https://www.jacoco.org/jacoco/[JaCoCo].  The link:{userManualPath}/jacoco_report_aggregation_plugin.html[jacoco-report-aggregation plugin] provides this ability when applied to the distribution project, such as an Android application or WAR subproject.

The project in this example contains three projects: `application`, `list` and `utilities`.  All three projects apply the `jacoco` plugin, and `application` consumes both `list` and `utilities` on its implementation configuration.  The `application` subproject is the final distribution of this software project, and applies `jacoco-report-aggregation` to perform the code coverage aggregation.

WARNING: The Test Report Aggregation plugin does not currently work with the ``com.android.application`` plugin.

====
include::sample[dir="kotlin",files="application/build.gradle.kts[]"]
include::sample[dir="groovy",files="application/build.gradle[]"]
====

The `application` project requires no additional configuration if the `jvm-test-suite` plugin is present.

<1> Apply the `jacoco-report-aggregation` plugin
<2> Optional: make JaCoCo aggregate report generation part of the 'check' lifecycle phase

The report aggregation logic does not automatically inspect all subprojects for coverage data to aggregate.  Instead, the direct and transitive link:{userManualPath}/declaring_dependencies_basics.html#sec:project-dependencies[project dependencies] of the distribution project's runtime classpath are selected for potential aggregation.

For the default test suite named 'test', no additional configuration is necessary.  The aggregated reports and their backing tasks of type `JacocoReport` are synthesized based on the test suites existing in the `application` project.  Test suites having identical `testType` properties will be aggregated.

Running the tests and generate the report:

[listing.terminal.sample-command]
----
$ ./gradlew testCodeCoverageReport

BUILD SUCCESSFUL
25 actionable tasks: 25 executed
----

XML and HTML reports can now be found under `application/build/reports/jacoco/testCodeCoverageReport`.

For more information, see link:{userManualPath}/java_testing.html[Testing in Java project chapter].
