I'm working on a multi-module project that employs a standalone sub-project to aggregate coverage reports. The project is build using Gradle, employing the Jacoco report aggregation plugin for Gradle.
Currently, the coverage report is generated in HTML format only. However, I specifically need the XML file format so that I can incorporate it into an artifact within Azure DevOps pipeline.
The root project and sub-projects have the following build.grade
configuration files:
Root project
plugins {
id 'java'
}
sourceCompatibility = '17'
allprojects {
repositories {
mavenCentral()
}
tasks.withType(Test.class).tap {
configureEach {
useJUnitPlatform()
}
}
}
One of the sub-projects
plugins {
id 'java'
id 'jacoco'
}
dependencies {
...
}
The standalone coverage sub-project
plugins {
id 'java'
id 'jacoco-report-aggregation'
}
bootJar {
enabled = false
}
jar {
enabled = false
}
dependencies {
jacocoAggregation project(':sub-project1')
jacocoAggregation project(':sub-project2')
}
The root project settings.gradle
file, just for completeness:
rootProject.name = 'my root project'
include 'sub-project1'
include 'sub-project2'
include 'coverage'
To generate the reports I'm using the following Gradle command:
> gradle clean build jacocoTestReport
In a different project with no sub-projects, I was able to generate the XML file by configuring up the Jacoco plugin report like this:
build.grade
jacocoTestReport {
reports {
xml.required = true
csv.required = false
}
Yet, I haven't be able to generate the XML format so far, for the multi-module project.
Any suggestions or clues wild be greatly appreciated.
The solutions can be found in this sample from the Gradle site.
The root and sub-projects build.settigns
files are correct in my question.
But for the coverage project the build.settings
is missing a dependency
The corrected file should be:
plugins {
id 'java'
id 'jacoco-report-aggregation'
}
bootJar {
enabled = false
}
jar {
enabled = false
}
dependencies {
jacocoAggregation project(':sub-project1')
jacocoAggregation project(':sub-project2')
}
//as in sample for the case you want to build the report when you run check
tasks.named('check') {
dependsOn tasks.named('testCodeCoverageReport', JacocoReport)
}
And to generate the aggregate report the command line should be:
$ ./gradlew testCodeCoverageReport
Note that invoking the task jacocoTestReport
will not build the aggregate report.
The report will be generated at <coverage project path>/build/reports/jacoco/testCodeCoverageReport
.
The XML file will also be generate there there. It's not necessary to enable CSV report format with the aggregate report plugin.