Sonar does not show code coverage in multiple Gradle projects

Hi,
I have a Spring Boot project consisting of two modules: ProjectA, which contains the SpringBootApplication annotation, and Adaptor, which ProjectA depends on.

When running integration tests in ProjectA through SpringBootTest and MockMvc, Jacoco generates a report in ProjectA that includes code coverage for both ProjectA and Adaptor classes.

However, after uploading to Sonar, it only displays code coverage for ProjectA, while Adaptor’s code coverage is reported as 0%. Could someone help me resolve this issue?

Some configurations:

plugins {
id "org.sonarqube" version "4.4.1.3373"
}
sourceSets {
    integrationTest {
        compileClasspath += sourceSets.main.output
        runtimeClasspath += sourceSets.main.output
    }
}

task integrationTest(type: Test) {
    group = 'verification'

    testClassesDirs = sourceSets.integrationTest.output.classesDirs
    classpath = sourceSets.integrationTest.runtimeClasspath
    shouldRunAfter test
    testLogging.showStandardStreams = true
}

integrationTest {
    failFast = true
    useJUnitPlatform()
    finalizedBy jacocoTestReport
}

def jacocoExecutionDataFiles = fileTree(buildDir).include("/jacoco/*.exec")
jacocoTestReport {
  
    getExecutionData().setFrom(jacocoExecutionDataFiles)
    reports {
        xml.required = true
        xml.outputLocation = file("$buildDir/reports/jacoco-it/test/jacocoITTestReport.xml")
        csv.required = false
        html.required = true
        html.outputLocation = file("$buildDir/reports/jacoco-it")
    }
}


sonar {
        apply plugin: 'java-library'
        apply plugin: 'org.sonarqube'
        properties {
            property "sonar.verbose", "true"
            property "sonar.sourceEncoding", "UTF-8"
            property "sonar.java.sources", "src/main"
            property "sonar.java.tests", "src/test"
            property "sonar.java.binaries", "$buildDir/classes/java/main"
            property "sonar.java.test.binaries", "$buildDir/classes/java/test"
            property "sonar.java.coveragePlugin", "jacoco"
            property 'sonar.coverage.jacoco.xmlReportPaths', "$buildDir/reports/jacoco-it/test/jacocoITTestReport.xml"
            property "sonar.junit.reportPaths", "$buildDir/test-results/test"
        }
    }

Hi,

I suspect this is a referencing problem. If you look the test report, does it have the correct paths from ProjectA, up and over to the Adaptor classes?

 
Ann

Yes, it’s definitely a referencing problem. At the top of the test report, it has <report name="ProjectA">; all the package and class paths are correct. After I manually updated the report name from ProjectA to Adaptor, Sonar could recognize the Adaptor code coverage.

How can I update the JaCoCo configuration to solve this referencing problem?

Hi,

Sorry, but that’s a question for the JaCoCo folks.

 
Ann