If SonarQube's results are not aren't relevant, developers will push back on using it. That's why precisely configuring what to analyze for each project is a very important step. Doing so allows you to remove noise, like the issues and duplications marked on generated code, or the issues from rules that are not aren't relevant for certain types of objectobjects.
SonarQube gives you several options for configuring exactly what will be analyzed. You can
Some project modules should not be analyzed and consolidated with global project measures. For instance: sample modules, integration tests modules, etc. To exclude those modules, at the project level, go to Configuration > Settings > Exclusions > Files and set the Module Exclusions property. The format is a comma-separated list of modules:
module1_to_exclude,module2_to_exclude. If a module's artifactId differs from its module name (the directory name), it is use the artifactId that should be used instead of the module name
You can also work the other way around with inclusions by setting the Module Inclusions property to a list of only those modules you want analyzed. Be careful: the root project must be added to the list.
Most language plugins offer a way to restrict the scope of analysis to files matching a set of extensions. Go to Settings > General Settings > LanguagePlugin and set the File suffixes property:
It is possible to exclude specific files from being analyzedanalysis. At the project level, go to Configuration > Settings > Exclusions > Files and set the:
Since version 3.5, you can also work the other way around by setting inclusions. Go to Settings > General Settings > Exclusions > Files and set the
sonar.test.inclusions properties to the list of files that should be analyzed. If you set an inclusion, then only the files or modules listed there will be included in the analysis.
Note that the properties below properties can only be set through the web interface because they are multi-valued.
Restrict Scope of Coding Rules
You can restrict the application of a rule to only certain components, ignoring all others.
- I only want to check the rule Magic Number on Bean objects and not on anything else =>
- I only want to check the rule Prevent GO TO statement from transferring control outside current module on COBOL programs located in the directories bank/creditcard and bank/bankcard => this one requires two criteria to define it: