SonarQube define "Ignore Issues on Multiple Criteria" in maven build

2.9k views Asked by At

Is it supported by sonar-maven-plugin to set the "Ignore Issues on Multiple Criteria" to Narrow the focus as -Dsonar.issue.ignore.multicriteria for the sonar-maven-plugin run command?


Any working example is welcomed.

2

There are 2 answers

2
Eitan Volach On BEST ANSWER

I have created similar setup in my project, as we needed to set the exclusions from the maven command (same as you), and not via the sonar gui (Sonar documentation only refers to exclusions via sonar's gui) Here's what we did in our project:

"-Dcommon.sonar.issue.ignore.multicriteria=e1,e2 " +
"-Dcommon.sonar.issue.ignore.multicriteria.e1.ruleKey=squid:S1845 " +
"-Dcommon.sonar.issue.ignore.multicriteria.e1.resourceKey=**/input/**/*.java " +
"-Dcommon.sonar.issue.ignore.multicriteria.e2.ruleKey=squid:S1845 " +
"-Dcommon.sonar.issue.ignore.multicriteria.e2.resourceKey=**/datatypes/**/*.java"

We also had these additional exclusions, i thought would be of assistance to the public:

"-Dsonar.issue.ignore.allfile=r1,r2 " +
"-Dsonar.issue.ignore.allfile.r1.fileRegexp=@Input\\(.*\\) " +
"-Dsonar.issue.ignore.allfile.r2.fileRegexp=@Output\\(.*\\)"
0
Isaiah4110 On

An additional note for people ending up on this answer. I tested this quite a lot and finally found that setting common rules (anything that starts with "common-xxxx") from scanner side (pom, command line etc) will be ignored and wont work. The language specific rules can be passed line arguments and thats why the "squid:S1845" rule is getting ignored correctly. Here is the issue link on the SonarQube JIRA board and it says that it "wont be fixed".

https://jira.sonarsource.com/browse/SONAR-8230

Here is the link to my answer: https://stackoverflow.com/a/60570763/1766402