Duplication detection

747 views
Skip to first unread message

arjen.v...@gmail.com

unread,
Dec 9, 2015, 11:07:51 AM12/9/15
to SonarQube
Hi,

Lately I have been trying to find duplicates in my codebase with SonarQube 4.5.
For both C++ and Java projects.
However I don't really like the results. Although I don't get 'any' false positives, it does fail to detect quite some duplication.

- It only detects fairly large duplications (I would prefer 6 lines or more instead of 10 statements, or to be able to configure this)
- It only supports detection across multi-modules if the cross-project setting is on (however I don't want cross project, just cross subproject/module)
- It seems that for cross module detection you need to run analysis twice in a row to remove false positives (else when a duplicate is fixed, you get a duplicate on module A from B, while B does not raise a duplicate for A, since it was fixed)

My questions:
- Will it be possible to configure the duplication size in a future SonarQube ?
- Will there be an option to enable cross-module, but not cross-project detection in a future SonarQube ?

Regards,
Arjen

G. Ann Campbell

unread,
Dec 9, 2015, 11:52:42 AM12/9/15
to SonarQube, arjen.v...@gmail.com
According to the docs you can tune duplicate block size with sonar.cpd.[language].minimumTokens and sonar.cpd.[language].minimumLines. :-)

Cross-everything duplication was dropped in SonarQube Server version 5.2 because of time constraints. Cross-project duplication returns in 5.3. Cross-module duplication will come later.


Ann

On Wednesday, 9 December 2015 11:07:51 UTC-5:

arjen.v...@gmail.com

unread,
Dec 10, 2015, 7:09:25 AM12/10/15
to SonarQube, arjen.v...@gmail.com
I know the docs mention those parameters, however they don't seem to work for Java. 
If I run a "mvn sonar:sonar -Dsonar.cpd.java.minimumLines=6" or "mvn sonar:sonar -Dsonar.cpd.java.minimumLines=40", it does not have any effect.

Or do I do something wrong ?

Cross-module (or at least project) duplication seems like a must have for java projects. Since most projects consist of a bunch of small maven modules instead of one large code-base, chances of inner module duplication are small. So I'm glad it still is on the roadmap for 5.3 and later.

Arjen

Julien HENRY

unread,
Dec 14, 2015, 5:49:59 AM12/14/15
to SonarQube, arjen.v...@gmail.com
Hi,

Java is a special case and have a dedicated CPD algorithm (based on statements). So it doesn't have any property to tune.

For cross module detection I confirm that it was requiring to run analysis twice. Will be probably fixed in 5.4.

++

Julien

G. Ann Campbell

unread,
Dec 14, 2015, 8:59:42 AM12/14/15
to SonarQube, arjen.v...@gmail.com
Thanks @Julien! I've updated the docs.


Ann


On Monday, 14 December 2015 05:49:59 UTC-5, Julien HENRY wrote:
Hi,

Java is a special case and have a dedicated CPD algorithm (based on statements). So it doesn't have any property to tune.

For cross module detection I confirm that it was requiring to run analysis twice. Will be probably fixed in 5.4.

++

Julien

Le jeudi 10 décembre 2015 13:09:25 UTC+1, :

arjen.v...@gmail.com

unread,
Dec 14, 2015, 10:40:47 AM12/14/15
to SonarQube, arjen.v...@gmail.com
To bad it is not possible for Java :(
But thanks for answering the question!

Julien HENRY

unread,
Dec 14, 2015, 10:41:37 AM12/14/15
to SonarQube, arjen.v...@gmail.com
And to be complete in Java a duplication block should contain at least 10 statements.
Reply all
Reply to author
Forward
0 new messages