SonarCloud - Ignore code blocks option

Hi everybody,

I want to ignore specific blocks in my code.

I test the sonar.issue.ignore.block, but it’s seems not working. I test with UI configuration, but also with configuration directly in the pom.xml file or in the command line even if it’s not recommended. It never works.

I found two others topics with more or less the same problem but the answers were unclear.
Can I have a clear answer? This option is functional or not?

  • ALM used : GitHub
  • CI system used : CircleCI
  • Scanner command used when applicable (private details masked) :
    mvn sonar:sonar -DsourceEncoding=UTF-8 -Dsonar.organization=XXX -Dsonar.projectKey=XXX -Dsonar.login=XXX
  • Languages of the repository : Java
  • Steps to reproduce :

A example of specific blocks to ignore :

UI configuration :

Result :

SonarScanner Context :

Project server settings:

  • sonar.branch.longLivedBranches.regex=(master|develop)
  • sonar.exclusions=pom.xml
  • sonar.issue.ignore.block=1
  • sonar.issue.ignore.block.1.beginBlockRegexp=// @SONAR_STOP@
  • sonar.issue.ignore.block.1.endBlockRegexp=// @SONAR_START@
  • sonar.junit.reportPaths=/target/surefire-reports
  • sonar.pullrequest.provider=GitHub
  • sonar.scm.disabled=false

Hey there.

It looks like you’re ignoring issues in blocks, rather than coverage. There is not an equivalent setting for coverage (you can ignore at the file-level via Coverage Exclusions, but not blocks of code).

Therefore, it’s really down to what your coverage tool is reporting as an executable line.

Why do you want to exclude this code from coverage? Is it generated code, something else…?

1 Like