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


Charles Nutter & Guillaume Laforge Okke en Rudie Joshua Bloch at JavaOne2008 Tim Bray introducing the (J)Ruby panel Hotel room Stage being build in the nearby park alcatraz Moscone Center - JavaOne Golden Gate sea_lion golden_gate_warning_sign javaone2008 keynote Scribbled Sun Logo Rudie javaone 2008 goodybag smashmouth Greenland Acme Anvile at CommunityOne Keynote Stretched Limo nearby hotel
View more photos >

Categories



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