Sonarcloud.io ignores jacoco xml report

sonarcloud.io ignore jacoco xml report

gradle version - 6.8.3
sonarqube - sonarcloud.io (paid plan\subscription)
jacaco plugin version - 0.8.7
sonarqube plugin version - 0.3.2

Problem: sonarcloud.io ignore jacoco xml report and not showing correct code coverage percentage, even with xml enabled true and explicit xml report path. The debug log say ‘XML Sensor’ skipped because there is no related file in current project. But also saying that Sensor JaCoCo XML Report Importer [jacoco] (done) | time=70ms. I reviewed other topics and issues with same error [Coverage & Test Data] Importing JaCoCo coverage report in XML format , gradle - 0% Coverage in the SonarQube report for the Kotlin project - Stack Overflow but the didn’t help me to solve the problem with jacaco xml report test coverage. I found the solution that partially solves the problem with sonar.exclusions option. But what is wrong with jacoco plugin and why it is not working?

build.gradle

plugins {
id ‘jacoco’
id ‘org.sonarqube’ version ‘3.2.0’
}

jacoco {
toolVersion = “0.8.7”
}

jacocoTestReport {
reports {
xml.enabled true

}
afterEvaluate {
    classDirectories.setFrom(files(classDirectories.files.collect {
        fileTree(dir: it, exclude: [
                'com/platform/serivce/config/*/**',
                'com/platform/serivce/api/data/*',
                'com/platform/serivce/model/*'
        ])
    }))
}

}

test {
finalizedBy jacocoTestReport
}

tasks[‘sonarqube’].dependsOn test

sonarqube {
properties {
property(“sonar.projectKey”, “my_project_key”)
property(“sonar.organization”, “my_organization”)
property(“sonar.host.url”, “https://sonarcloud.io”)
property(“sonar.coverage.jacoco.xmlReportPaths”, “build/reports/test/jacocoTestReport.xml”)
}
}

cli command:

gradle clean sonarqube -Dsonar.login=my_login

html report

sonarcloud

debug log piace

Hello @Maksat

I looked into your post and have a few questions.

You mentioned that you reviewed other topics with the same error that partially solved the problem, can you go into more details on this?

Are you running your analysis locally or on CI?

Is your code coverage for the same language?

Is it possible for you to share your private key with us so that we can investigate further? I will create a private message in the meantime for you to share your private key with us if you decide to.

Regards,

Justin

Hello @Justin_Allen, thank you for reply.

  1. Yes, the best way I found to solve this problem is to use property “sonar.exclusions” and exclude same files as in jacocoTestReport. But still coverage is not the same, there still 1-5% difference in code coverage.
  2. The result is the same both for ci and local run;
  3. Yes code coverage is the same, language is java, spring boot framework.

And no, i will not share my private key. Sounds like scam request )))

@Maksat
To clarify “XML Senor ‘ skipped ” does not have an impact on code coverage in your analysis.

Can you let me know if you are using another tool to provide the coverage? If jacoco is the only tool used then it is not being ignored, as code coverage information is visible on SonarCloud.

@Justin_Allen no we use only jacoco

Thanks @Maksat

Can you review the output of the scanner in between the 2 lines below? You should see information on the missing files between these lines.

INFO: Sensor JaCoCo XML Report Importer [jacoco]

INFO: Sensor JaCoCo XML Report Importer [jacoco] (done) | time=2ms

Please let me know if this doesn’t help

@Justin_Allen, here those two lines


But still coverage is not the same

Hello Maksat,

If your source code and coverage report are the same as what was analyzed, can you compare the coverage for each directory and file in the local report with the coverage generated on SonarCloud and let me know if there are any discrepancies at directory level, such as missing files?

Can you also attach a screenshot of the Overall coverage from the Coverage Overview in SonarCloud?

1 Like