Add sources from other module to jacoco report


(Ralph van Etten) #1

I have a project which consists of two modules: serverlib and testserver:

- serverlib
  - src/main/java   <-- also tested by testserver
- testserver
  - src/main/java 
  - src/test/java   <-- integrationtests

serverlib contains classes which are used by testserver and are tested by the integration tests for testserver. I’ve setup integration tests according to the documentation in the gretty plugin. This all works but Jacoco only shows the coverage of the code for testserver

How can I include coverage for serverlib in the Jacoco report generated when running the integration test for testserver ?

Relevant parts of my build.gradle:

dependencies {
    compile project(":serverlib")   // <-- these classes should also appear in the coverage report
}

task('integrationTest', type: Test) {
    include '**/*IT.*'
}

tasks.test {
        exclude '**/*IT.*'
}

gretty {
  afterEvaluate {
      tasks.appBeforeIntegrationTest.jacoco {
          append = false
          destinationFile = project.file("$project.buildDir/jacoco/integrationTestServer.exec")
      }
      tasks.appAfterIntegrationTest.finalizedBy tasks.integrationTestServerReport
}

task('integrationTestServerReport', type: JacocoReport) {
        executionData { tasks.appBeforeIntegrationTest.jacoco.destinationFile }

        sourceDirectories = files(sourceSets.main.allSource.srcDirs)
        classDirectories = sourceSets.main.output

        def reportDir = reporting.file("jacoco/integrationTest_server/html")
        reports {
            html.destination = reportDir
        }
    }

(Jeetendra Kukreja) #2

I’m looking for the same information. Is it possible to add sources from other (dependent modules) to the module where the jacoco plugin is applied? Has anyone done this? My setup is the following

serviceModule1
serviceModule2
appModule (dependent on serviceModule1 and serviceModule2)

  • build.gradle contains a run task and the jacoco plugin is applied to that task the execution data is set as the run task

code coverage is reported only for source in the the appModule task i.e. my.packages.appModule. Is it possible to include the sources from serviceModule1 and serviceModule2 in the report?