Sonar Exclusion blocks within files and Jacoco Coverage Report issue

Must-share information (formatted with Markdown):

  • SonarQube Scanner - 4.7.0.2747
  • Run Sonar scanner on Bitrise(CI) workflows
  • Skip/Exclude blocks of code in classes.
  • Used \s*//\s*START-NOSCAN and \s*//\s*END-NOSCAN as exclusion properties on the UI as suggested in Narrowing the focus with an analysis scope.

In our CI workflow, we produce a consolidated jacoco report and there is an current issue with Jacoco unable to exclude certain parts of Jetpack Compose code. For e.g. We would want to exclude all the @Preview composables from code coverage. They are used for dev purposes and are not used in production.

For e.g.

// BEGIN-NOSCAN
@ExcludeFromJacocoGeneratedReport <-- This does not work due to the Jacoco Issue, only in Compose Previews.
@Preview
@Composable
private fun DigitalInvoiceSignaturePadPreview() {
    SignaturePad()
}
// END-NOSCAN

Now, I am wondering if the sonar exclusion properties work if the analysis is done outside of sonar and a coverage report is provided to Sonar.

Please let me know if there are any other configs in Sonar that would help.

Thanks.

Hi,

Coverage exclusions only work at the file level. Even within SonarQube, Ignoring blocks within files only works for issues. Even if they did work for coverage, there’s no rule or even convention for how to specify blocks. You configure into SonarQube whatever existing markers in your code mark the blocks to be excluded. So there’s no way for other tools to know or honor what’s being excluded by SonarQube.

 
HTH,
Ann