Darren Oakey
Darren Oakey

Reputation: 3662

Jacoco gradle multi module

We have a gradle project with mutliple modules - so each module - eg admin, ends up having something like this:

task admintest(type: Test) {
    description = "Tests of admin"
    testClassesDir = sourceSets.admintest.output.classesDir
    classpath += sourceSets.admintest.runtimeClasspath
}
check.dependsOn admintest

now - we are generating a jacoco report - the report actually includes all the classes from all the different modules, but only has coverage from the tests that ran as part of the main module, ie the "test" task - while the admintests and others run, the coverage is always zero. How do I get jacoco to also pick up the coverage from the admintests, and other module tests?

Upvotes: 3

Views: 2678

Answers (2)

Ram Pratap
Ram Pratap

Reputation: 530

This is old thread , but this might help someone :

We only need this in build.gradle of root project.

  1. Define a common location

  2. Provide same to sonarqube as well.

     plugins {
         ..
         id "org.sonarqube"
     }
     apply plugin: 'org.sonarqube'
    
     allprojects {
         apply plugin: 'jacoco'
     }
    
     task jacocoRootReport(type: JacocoReport) {
         dependsOn = subprojects.test
         description = 'Generates aggregate report from all subprojects.'
         .....
         reports {
             xml.enabled true
             xml.destination(file("${jacoco.reportsDir}/all-tests/jacocoRootReport.xml"))
             csv.enabled false
         }  
     }
    
     sonarqube {
         properties {
            property "sonar.coverage.jacoco.xmlReportPaths", jacocoRootReport.reports.xml.destination
         }
     }
    

Upvotes: 0

Darren Oakey
Darren Oakey

Reputation: 3662

Found it - for those who are trying to do this - the secret sauce is to specify the other modules test tasks in the executionData

eg:

jacocoTestReport {
    executionData test, admintest, commontest
}

Upvotes: 1

Related Questions