Disable Sonar duplications on Entity, DTO packages

39,570

Solution 1

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.

Solution 2

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
Share:
39,570
Arek
Author by

Arek

Updated on October 23, 2021

Comments

  • Arek
    Arek over 2 years

    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?