Questions regarding Sonarqube + Jacoco Code Coverage

Hello there,

Sonarqube Server (Community Edition): 7.9.2.30863/8.2.0.32929 or SonarCloud

  • with JaCoCo plugin 1.0.2 (build 475) installed
  • with SonarJava plugin 6.1 (build 20866) installed

Gradle: 6.2.1

  • Kotlin: 1.3.61
  • Groovy: 2.5.8
  • Ant: Apache Ant™ version 1.10.7 compiled on September 1 2019
  • JVM: 11.0.4 (Oracle Corporation 11.0.4+10-LTS)
  • OS: Windows 10 10.0 amd64

build.gradle.kts

plugins {
    java
    jacoco
    id("org.sonarqube") version "2.8"
}

repositories {
    jcenter()
}

dependencies {
    testImplementation("org.junit.jupiter", "junit-jupiter", "5.6.0")
    testRuntimeOnly("org.junit.vintage", "junit-vintage-engine", "5.6.0")
    testImplementation("junit", "junit", "4.13")
}

tasks {
    test {
        useJUnitPlatform()
    }
    jacocoTestReport {
        reports {
            xml.isEnabled = true
        }
    }
}

sonarqube {
    properties {
        property("sonar.projectKey", "calculator")
        property("sonar.host.url", "http://localhost:9001")
        property("sonar.sourceEncoding", "UTF-8")
        property("sonar.sources", "src/main/java")
        property("sonar.tests", "src/test/java")
        property("sonar.java.coveragePlugin", "jacoco")
        property("sonar.java.binaries", "$buildDir/classes/java/main")
        property("sonar.java.test.binaries", "$buildDir/classes/java/test")
        property("sonar.junit.reportPaths", "$buildDir/test-results/test")
        property("sonar.coverage.jacoco.xmlReportPaths", 
"$buildDir/reports/jacoco/test/jacocoTestReport.xml")
    }
}

Running Gradle build by ./gradlew clean build jacocoTestReport sonarqube --info

Questions:

  1. The coverage percentage displayed is about zero. I guess this could be caused by the issue reported back in July 2019 - Java classes with default package.
    Do we have any ETA for the bug to be fixed? Do we know any workaround except moving the source code to a package?

  2. With the above mentioned Sonarqube configuration where “new” sonar.coverage.jacoco.xmlReportPaths and sonar.junit.reportPaths are using, I still see the warnings about obsolete properties:
    Property 'sonar.jacoco.reportPath' is no longer supported. Use JaCoCo's xml report and sonar-jacoco plugin.
    Property 'sonar.jacoco.reportPaths' is no longer supported. Use JaCoCo's xml report and sonar-jacoco plugin.
    Could you suggest any way to fix/skip them? I have another Gradle project with 800+ subprojects in there, which generates 1600+ lines of warning in total.

Any help is highly appreciated.

Thank you!

Hello @paranoiduser,

You can have a look at the logs to see if nothing else went wrong, but indeed, if you are using default package, you are probably affected by this issue. I can not give you an ETA, but thanks for raising the point, we will see what we can do about it.

This issue is already fixed, it will be included in SonarJava 6.2. No quick workaround in-between, but we are almost done with 6.2, it will be available soon enough.

Hope this clarifies the situation.

Best,
Quentin

Hi @Quentin,

Thank you for your reply. I see the warnings from the issue (2) are gone and logs look much clear now.

Regarding the issue with default package coverage, do you see any workaround here? We temporarily disabled code coverage metrics to pass the Quality Gate, and unblock release process. Unfortunately, I cannot modify the source code, but I can try to move our tests to another package if it helps, shall I?

Thanks in advance!

Glad to see that logs are clearer now.
Concerning coverage, I’m afraid I have no work-around in mind. Please let us know if you find something working for you.
By saying that, I realize that this is pretty bad… I will see what we can do to improve the situation.

please let me know if I need to move them into a separate topic

Yes, please! Especially since it is not obviously related to the initial problem reported.

Best,
Quentin

Thank you @Quentin, for your assistance!
Looking forward to seeing the fix in action :wink: