Duplication Criteria in Sonar

2.6k Views Asked by At

I have followed below link which is for Java Script

Sonarqube: Is it possible to adapt duplication metric for javascript code?

Similarly I have done for my Java project. And as per this if we wish to change the duplication criteria, i.e. by default 10 lines, we have to add one line in sonar.properties file which is stored in project.

sonar.projectKey=Test
sonar.projectName=Test
sonar.projectVersion=1.0
sonar.sources=src
sonar.language=java
sonar.sourceEncoding=UTF-8
sonar.cpd.java.minimumLines=5 

But its not working for Java, is there anything else I need to configure?

1

There are 1 best solutions below

3
On

Per SonarQube's Duplications documentation:

A piece of code is considered duplicated as soon as there are at least 100 successive and duplicated tokens (can be overridden with property sonar.cpd.${language}.minimumTokens) spread on at least 10 lines of code (can be overridden with property sonar.cpd.${language}.minimumLines). For Java projects, the duplication detection mechanism behaves slightly differently. A piece of code is considered as duplicated as soon as there is the same sequence of 10 successive statements whatever the number of tokens and lines. This threshold cannot be overridden.