CPD with maven2 and PMD
Published by peter November 14th, 2007 in cpd, java, maven.Detecting copy/pasted code is a useful technique to find potential buggy code. Duplicated code often results in bugs being fixed in only one version of the copied code. PMD is a great sourcecode analysis tool which integrates nicely with maven and has CPD (copy/paste detection) capabilities.
To configure with default settings and CPD support add the following to the pom:
-
<plugin>
-
<groupId>org.apache.maven.plugins</groupId>
-
<artifactId>maven-pmd-plugin</artifactId>
-
<configuration>
-
<sourceEncoding>utf-8</sourceEncoding>
-
<minimumTokens>100</minimumTokens>
-
<targetJdk>1.5</targetJdk>
-
</configuration>
-
</plugin>
You can configure the minimum code size which trips the CPD. The default of 100 tokens corresponds to approximately 5-10 lines of code.
Generated reports look like this and show the file in which the duplicates where found and the duplicated code:
Really useful, great hooks for DRY-ing out code!




















0 Responses to “CPD with maven2 and PMD”
Please Wait
Leave a Reply