Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable Sonar duplications on Entity, DTO packages

Is there any way to disable certain metrics from selected packages in Sonar? I use Sonar to analyze my project and in Entity and DTO packages I have some code that is equal - the same field ID with annotations, etc is being reported as a duplication by Sonar. It has absolutely no sense to me so I'd like to disable it. How can I achieve this? Using the global exclusions option disables all metrics on selected package but how to do it just for code duplications?

like image 847
Arek Avatar asked Jun 18 '12 08:06

Arek


People also ask

What is duplications SonarQube?

SonarQube detects duplications in files and projects and also across projects. SonarQube reports duplication by line, block, and file. If you've lived through this type of situation, you already know that duplicate code is one of the highest risk factors for bug propagation.

How do you use sonar CPD exclusions?

cpd. exclusions is shown in the SonarQube settings when you navigate to: Project settings > General Settings > Analysis Scope. This is the correct answer for modern Sonar versions -- the accepted answer was the only workaround back in 2012.


2 Answers

With a newer SonarQube installation, you can use sonar.cpd.exclusions to exclude certain files only from duplicate checks. See: https://docs.sonarqube.org/display/SONAR/Analysis+Parameters

Example:

sonar.cpd.exclusions=**/AssemblyInfo.cs,**/*.g.cs,**/Mappings/*.cs 
like image 90
Roemer Avatar answered Sep 18 '22 03:09

Roemer


You can exclude resources using the standard "sonar.exclusions" parameter or use the Switch Off violation plugin to exclude "Duplicated code" violations.

Note that the 2nd option (use of the switch off plugin) works only if you're using the SQALE plugin, which embeds the "sqale-java:DuplicatedBlocksCheck" rule.

like image 27
Fabrice - SonarSource Team Avatar answered Sep 18 '22 03:09

Fabrice - SonarSource Team