CPD with maven2 and PMD

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:

[xml]

org.apache.maven.plugins
maven-pmd-plugin

utf-8
100
1.5
[/xml]

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:

CPD Report

Really useful, great hooks for DRY-ing out code!

This entry was posted in cpd, java, maven. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>