2

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?

Community
  • 1
  • 1
swapnil
  • 51
  • 1
  • 8
  • http://stackoverflow.com/a/14412802/2893693 – Jobin Jan 03 '17 at 09:09
  • try removing `sonar.language=java` from sonar 4.2, multi-language projects are supported. This automatically happens when sonar.language is not set. – Jobin Jan 03 '17 at 09:10

1 Answers1

3

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.

Nicolas B.
  • 7,245
  • 17
  • 29
  • Do you have a public link to this documentation? It says "Not Permitted" for me. Additionally... are there plans to make this configurable for Java? – Christian Apr 04 '18 at 06:43
  • 1
    Documentation apparently evolved, Duplications are still explained [here](https://docs.sonarqube.org/display/SONAR/Metric+Definitions). – Nicolas B. Apr 04 '18 at 14:28
  • Now the documentation does not say that this limit cannot be overridden. Though setting the limits for java does not actually work. Now can I set those limits or not? – Árpád Magosányi Mar 18 '19 at 17:49