How do I use jacoco plugin with a multi module build in order to produce one jacoco xml output file (and report) containing the coverage for all subprojects?
Also I found I had to add updated the jacocoClasspath like this: jacocoClasspath += files(
Related to this, as of 1.7, one must still set jacocoClasspath on custom JacocReport tasks, which is quite sad. As for the original question, if you don’t care about having the merged binary data file, you can simplify your gradle script a bit:
subprojects {
apply plugin: "java"
apply plugin: "jacoco"
test {
// Don't instrument and generate code coverage unless "-Pcodecoverage" is set on the command line
jacoco {
enabled = project.hasProperty("codecoverage")
}
}
}
configurations {
jacoco {
description "JARs required for doing our own JacocoReport tasks"
}
}
dependencies {
jacoco 'org.jacoco:org.jacoco.ant:0.6.2.201302030002'
}
task jacocoReport(type: JacocoReport) {
jacocoClasspath = configurations.jacoco
// Add execution data from all subprojects
executionData fileTree(project.rootDir.absolutePath).include("*/build/jacoco/*.exec")
// Add source classes from all subprojects
subprojects.each {
sourceSets it.sourceSets.main
}
// Make the aggregate report go in a top-level directory somewhere
reports {
html {
enabled true
destination "release/reports/jacoco"
}
}
}