Code coverage published to Sonar is not correct

We’re using Sonar Server 9.1 and using maven command to publish reports to Sonar along with code coverage generated through Jacoco

In index.html file generated for code coverage, we can see code coverage as - 68% but when used jacoco.xml file to publish to Sonar it’s showing only 48.6% code coverage on Sonar.

What analysis I should do to find the cause of discrepancy?


Your coverage provider is only going to report on the files you’ve told it to. What I mean is that if you’ve excluded a file from coverage, your provider will ignore it. But in calculating your overall coverage %, SonarQube does not.

This blog post has some age on it, but it’s still a good explanation of what’s going on.