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:
  1. <plugin>
  2.   <groupId>org.apache.maven.plugins</groupId>
  3.   <artifactId>maven-pmd-plugin</artifactId>
  4.   <configuration>
  5.     <sourceEncoding>utf-8</sourceEncoding>
  6.     <minimumTokens>100</minimumTokens>
  7.     <targetJdk>1.5</targetJdk>
  8.   </configuration>
  9. </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:

CPD Report

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


0 Responses to “CPD with maven2 and PMD”

  1. No Comments

Leave a Reply





About

Welcome to the weblog of Peter Maas. Here you'll find various posts related to stuff I like (like my kids and espresso) and stuff I do (like developing software).

JavaOne 2008 Pictures


Acme Anvile at CommunityOne Keynote Rudie Okke en Rudie Greenland Hotel room smashmouth alcatraz Golden Gate Tim Bray introducing the (J)Ruby panel Stretched Limo Charles Nutter & Guillaume Laforge Joshua Bloch at JavaOne2008 javaone2008 keynote Cable Car line Community One Keynote Stage being build in the nearby park nearby hotel Scribbled Sun Logo Java + You on a cab javaone 2008 goodybag
View more photos >

Categories



Meld u aan voor PayPal en begin direct met het accepteren van creditcardbetalingen.