How exactly does sonarcloud handle methods not in the jacoco xml?

This is for an Android app - I created an annotation which causes Jacoco to exclude some methods from the generated coverage XML. When I diff the XMLs it does exclude the method the the report.

I can’t just mark the files as excluded in the sonar properties because this is for @Preview code in Jetpack Compose, which needs to be in the same file as the actual component definitions (which should not be excluded).

When I push the code through CI and it gets sent to sonar, the code is still marked as uncovered, in the new code list.

The most I could find was that Sonar “uses the jacoco xml”, but does that mean that any methods not included in the XML are counted as uncovered? That seems to be at odds with the jacoco assumption that removing it means it is not counted.

If the file is present in the JaCoCo coverage report but the methods are absent, then SonarQube will assume those lines can’t be covered and not report that they aren’t covered.

If something else is happening, please feel free to share a small project where the issue can be easily reproduced.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.