SupercovBlog

Guide

sonar.coverage.exclusions: why SonarQube ignores your JaCoCo excludes

One project scanned six ways with SonarQube 26.11: which setting decides coverage, and which patterns match nothing.

Excluded in JaCoCo. Uncovered in Sonar. Two brushed-aluminum trays of white tiles: the left one has a violet tile lifted out, the right one still holds every tile.

SonarQube does not read JaCoCo’s excludes. Files missing from JaCoCo’s report count in SonarQube as uncovered. Set sonar.coverage.exclusions, with source paths such as **/dto/**, and SonarQube leaves them out of coverage.

sonar.coverage.exclusions vs sonar.exclusions

SettingWhat SonarQube does with matching files
sonar.coverage.exclusionsStill analysed for bugs and smells; left out of coverage
sonar.exclusionsLeft out of the whole analysis, issues included
JaCoCo’s <excludes>Nothing: SonarQube counts those files as uncovered

We ran each setup with SonarQube Community Build 26.11, the SonarScanner for Maven 5.9 and JaCoCo 0.8.16, on a Maven project with five classes: two with tests, a DTO package and an application class with a nested class. Without exclusions SonarQube reported 39.4% coverage.

Exclude files from coverage

<properties>
  <sonar.coverage.exclusions>**/dto/**,**/ShopApplication.java</sonar.coverage.exclusions>
</properties>

Coverage went to 81.3%: 8 of 10 lines and 5 of 6 branches, from Pricing and Receipt only. The same value on the command line, -Dsonar.coverage.exclusions=…, gave the same result.

It gave 81.3% whether or not JaCoCo excluded anything. SonarQube decides coverage scope from its own setting; JaCoCo’s excludes only change JaCoCo’s own HTML and its check goal. Keep both in step, or set only the SonarQube one if SonarQube is your gate.

SonarQube found target/site/jacoco/jacoco.xml without being told. Set sonar.coverage.jacoco.xmlReportPaths only for another path or for several modules.

The same exclusions, two numbers

With JaCoCo excluding shop/dto/** and shop/ShopApplication*.class and no SonarQube setting:

ReportCoverage
JaCoCo’s own HTML8 of 10 lines (80%)
SonarQube46.4%: 8 of 22 lines, the excluded files at 0%

SonarQube counted every line it considers executable in OrderDto.java and ShopApplication.java as uncovered, because the report had no data for them.

Bars of SonarQube coverage for five setups: no exclusions 39.4%, JaCoCo excludes only 46.4%, sonar.coverage.exclusions only 81.3%, both 81.3%, class-file patterns in sonar.coverage.exclusions 46.4%.
SonarQube's own setting decides coverage; JaCoCo's excludes do not.

Why your sonar.coverage.exclusions isn’t working

What we triedWhat happened
shop/dto/**, shop/ShopApplication*.classNothing excluded: SonarQube matches source paths, not classes
JaCoCo <excludes> only46.4%, the files counted as uncovered
sonar.exclusions81.3%, but the files lost their bugs and smells too
A grid of five setups against four files. No exclusions and JaCoCo excludes only keep all four files in coverage. sonar.coverage.exclusions and sonar.exclusions keep Pricing and Receipt. Class-path patterns keep all four.
Which files SonarQube counted in coverage, measured with SonarQube Community Build 26.11.

Patterns match source file paths from the project directory: **/dto/** worked, package-style and class-file patterns did not. Separate several patterns with commas.

What Supercov adds

npx supercov -- mvn test
npx supercov runs latest gaps

SonarQube shows one blended number per file. Supercov records which test covered each line, with branches and MC/DC, and names the missing case. See JaCoCo exclude for JaCoCo’s side and JaCoCo vs SonarQube coverage for how SonarQube blends lines and branches.

More coverage guides