>Adding FindBugs and DRY(CPD) Reporting to Maven3/Tycho

>Updated: Oct 9, 2010 – updated to reflect Maven 3.0 final.

One of the more important things I think an open source project can do is to fix bugs before they get out into the wild. If you can head off the bugs before they get loose you have more time for the fun stuff like feature work.

With Maven 3.0 and Tycho for eclipse, eclipse projects can now leverage the ease of use that Maven 2 has enabled for years to get Static Code Analysis run during builds. To add FindBugs and PMD’s Copy Paste Detector reports during your build add the following to your bundle’s pom.xml:

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>2.5</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>2.3.2-SNAPSHOT</version>
<configuration>
<findbugsXmlOutput>true</findbugsXmlOutput>
<failOnError>false</failOnError>
</configuration>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<configuration>
<sourceEncoding>utf-8</sourceEncoding>
<minimumTokens>100</minimumTokens>
<targetJdk>1.5</targetJdk>
<format>xml</format>
<failOnViolation>false</failOnViolation>
</configuration>
<executions>
<execution>
<goals>
<goal>cpd-check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

To generate the appropriate XML reports during your build:


mvn clean install

With Maven 3.0 final, the verify command is no longer necessary. The above will execute after the compilation phase and do the analysis. Findbbugs will create a findbugs.xml file in the bundles target directory. CPD will create a cpd.xml file in the same location. Currently for FindBugs you must use the 2.3.2-SNAPSHOT if running with Tycho otherwise not all dependencies are downloaded.

Note that if you add the build entries to your parent-pom.xml it will run FindBugs and CPD against all your projects including your test bundles. My recommendation is to try and limit the analysis only to particular bundles and exclude the test bundles.

You can see this in action here:

https://hudson.eclipse.org/hudson/view/WTP/job/cbi-wtp-wst.xsl.psychopath/

Advertisements
This entry was posted in build, clean code, eclipse, maven, release engineering, tycho. Bookmark the permalink.

3 Responses to >Adding FindBugs and DRY(CPD) Reporting to Maven3/Tycho

  1. yoel.abril says:

    >I have problems finding 2.3.2-SNAPSHOT findbugs plugin from repositories. ¿Where did you find it?[ERROR] Plugin org.codehaus.mojo:findbugs-maven-plugin:2.3.2-SNAPSHOT or one of its dependencies could not be resolved: Could not find artifact org.codehaus.mojo:findbugs-maven-plugin:jar:2.3.2-SNAPSHOT -> [Help 1]

  2. yoel.abril says:

    >Which maven repository contains the findbugs 2.3.2-SNAPSHOT version??Thanx, Juan.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s