1

I' working on a multi-module project that employs a standalone sub-project to aggregate coverage reports. The project is build using Gradle so it uses 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.

MiguelSlv
  • 14,067
  • 15
  • 102
  • 169

1 Answers1

0

The solutions is present in this sample from Gradle official 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 whore 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 //Invoke task `jacocoTestReport`  will not build the aggregate report as I was doing.

The report will be generated at <coverage project path>/build/reports/jacoco/testCodeCoverageReport.

The XML file will be generate there too. It's not needed to enable CSV report format with thebaggregate report plugin.

MiguelSlv
  • 14,067
  • 15
  • 102
  • 169