Discrepancy Between Local Jacoco Report and SonarQube Code Coverage

When running my Java project locally, the Jacoco report shows that the ConfigParamController class has INSTRUCTION: 71/80, indicating 90% code coverage done. However, when scanning the same project in Sonar v10.5.1, it reports 0% code coverage. Could someone help me resolve this issue?

Screenshot 1 and Screenshot 2 are from Jacoco report
Screenshot 3 is from SonarQube

Hey there.

Are you sure your analysis is reading in the coverage report at all? You can check in the logs.

Hi Colin,

If you look at the image below, it shows that the class is fully covered according to the local report. However, in the Sonar scan (second image), it indicates that some new lines still need to be covered.

Debug mode is enabled in Sonar, Jacoco report and the debug log has been attached here. Please review it and let us know why there is difference in local Jacoco Report and SonarQube Code Coverage report and where the exact problem lies.

jacoco_aggregate (2).zip (3.7 KB)

SonarLog.txt (65.5 KB)


Hey @naveens

The file path of your JaCoCo report you shared here is jacoco-repo.xml, but the logs show a different file path being imported:

INFO: Importing 1 report(s). Turn your logs in debug mode in order to see the exhaustive list.
DEBUG: Reading report '/opt/gitlab-runner/builds/63Yo1gy3/0/components/fabrick-it/pfm/pfmbackofficeillimity/pfmbackofficeillimity-web/target/site/jacoco/jacoco.xml'
INFO: Sensor JaCoCo XML Report Importer [jacoco] (done) | time=51ms

Are you sure all your reports (or the right report) is getting passed to sonar.coverage.jacoco.xmlReportPaths? The docs on Java Test Coverage can be found here.

Hi Colin,

Please ignore the jacoco-repo.xml file. Here, I’ve attached the jacoco.xml file which shared to Sonar, where code coverage has been added for the ConfigParamController class. However, the Sonar scan indicates that some new lines still need to be covered.

Also, we are confirmed that the correct report is being passed to sonar.coverage.jacoco.xmlReportPaths.

We suspect there might be a bug in Sonar related to this specific code coverage scan. Could you please assist us in resolving this issue?

Sonar_Jacoco.zip (2.0 KB)


Hey there.

Looking back at your post, I think I understand the confusion better.

Lines to Cover ≠ lines that remain to be covered, but lines that can be covered.

I think you think it means Uncovered Lines, which is actually a separate metric.