I’m using SonarQube on my Java projects, and want to eliminate code duplications from our code as far as possible.
My problem is that SonarQube’s code duplication detection doesn’t take into account method boundaries. It lists identical parts of files as duplications, and it often happens that a duplication starts in the middle of a method and ends in the middle of another. These can hardly be refactored.
Here is an example. Click on file MavenArtifactRepository.java in the upper right list box, and take a look at the 4th duplication block in the lower part of the page.
Is there any way to parameterize the code duplication detector plug-in to show duplications, which are syntactically coherent?
Currently you cannot achieve that by configuring SonarQube itself. However, you can try our tool, SourceMeter with its SonarQube plug-in, which implements an AST based clone detection and therefore it presents syntactically coherent duplications inside SonarQube. For an example, you may take a look at the online demo.