Merge Jacoco coverage reports for multiproject setups

(Andrew Pennebaker) #1

When using the Gradle JaCoCo plugin, it would be nice if the coverage reports for all subprojects were merged together, to make them easier to access. Could the next version handle multiproject setups better?

In the meantime, is there a manual configuration that makes gradle test jacoco perform this merging when run at the parent project level?

(François Guillot) #2

You can manually merge them using the jacoco merge task, constructing the executionData FileCollection by iterating on all your exec files.

(Kevin Scaldeferri) #3

Can you provide an example of how to use JacocoMerge?

(Lance Java) #4

Possibly the integration test

(Kevin Scaldeferri) #5

That integration test doesn’t actually appear to be merging subprojects and I couldn’t figure out a variation that seemed to work to merge my subprojects. I am admittedly mostly just a monkey pressing keys at random when it comes to Gradle, but a working example of this for a project with subprojects would be really useful.

(Ben Manes) #6

The JacocoMerge is probably more correct, but a common alternative is the jacocoRootReport style task. The example below is how you can create an aggregate report and publish to Coveralls. You can dig into the usage here if you run into problems.

task jacocoRootReport(type: JacocoReport, group: 'Coverage reports') {
  description = 'Generates an aggregate report from all subprojects'

  additionalSourceDirs = files(subprojects.sourceSets.main.allSource.srcDirs)
  sourceDirectories = files(subprojects.sourceSets.main.allSource.srcDirs)
  classDirectories = files(subprojects.sourceSets.main.output)
  executionData = files(subprojects.jacocoTestReport.executionData)

  reports {
    html.enabled = true
    xml.enabled = true

  doFirst {
    executionData = files(executionData.findAll { it.exists() })

coveralls {
  sourceDirs = subprojects.sourceSets.main.allSource.srcDirs.flatten()
  jacocoReportPath = "${buildDir}/reports/jacoco/jacocoRootReport/jacocoRootReport.xml"

Merging jacoco reports for coveralls
(Lance Java) #7

The integration test merges two test tasks within the same project. This could easily be adapted for a multiproject build.


task jacocoMerge(type: JacocoMerge) {
   subprojects.each { subproject ->
      executionData subproject.tasks.withType(Test)

(Kevin Scaldeferri) #8

Thanks, I’ve made some progress based on that, but now find myself running into problems like those described in All of the attempts I’ve made to exclude our generated source files either don’t work or run into the problem reported in

(José Andias) #9

This test is now present in