|
|
WS-Policy and moreFabian's Blog on WS-Policy and more |
|
Friday Sep 19, 2008
Running Findbugs with Ant Tasks for Maven
We have been using Findbugs for quite a while now to help us find and squash bugs before they can do any harm. It is an excellent tool. Findbugs is directly integrated into our Ant build scripts and is run with every build. Findbugs provides an Ant task that makes it easy to integrate into Ant. For the integration you have to install Findbugs of course or provide the libraries with the rest of the Metro workspace. We did not want to require a manual installation for every developer because that seemed just inconvenient. And we did not want to check the libraries into our workspace because that workspace and the downloadable distributables are already bigger than we would like them to be. Hence we chose an approach that I have not seen documented in its entirety anywhere else. The solution is primarily provided by the eminently useful Ant Tasks for Maven. They allow you to execute a couple of Maven related tasks from an Ant build script. And one of the useful things you can do with them is download Findbugs from a Maven repository within your Ant build script. Integrating the tasks is straight-forward: <target name="maven-init">
<typedef resource="org/apache/maven/artifact/ant/antlib.xml">
<classpath>
<pathelement location="lib/maven-artifact-ant-2.0.4-dep.jar" />
</classpath>
</typedef>
<remoteRepository id="maven.repository" url="http://www.ibiblio.org/maven2/"/>
</target>
The above makes sure Ant knows about the new Maven tasks and declares a repository from which we will be dowloading Findbugs. This target is designed to be reused by other targets, not just the one that is downloading Findbugs. But back to integrating Findbugs into our Ant script. This here does the interesting part of the work: <target name="findbugs-base" depends="maven-init">
<dependencies pathId="findbugs.classpath"
useScope="runtime">
<remoteRepository refid="maven.repository"/>
<dependency groupId="net.sourceforge.findbugs"
artifactId="findbugs"
version="1.3.2"/>
</dependencies>
<typedef name="findbugs" classname="edu.umd.cs.findbugs.anttask.FindBugsTask">
<classpath refid="findbugs.classpath"/>
</typedef>
<pathconvert property="findbugs.classpath">
<path refid="findbugs.classpath"/>
</pathconvert>
</target>
The <target name="findbugs-html" depends="findbugs-base"
<findbugs output="html"
outputFile="${build.dir}/findbugs.html"
stylesheet="fancy.xsl"
classpath="${findbugs.classpath}"
jvmargs="-Xmx256m"
pluginlist="${user.home}/.m2/repository/net/sourceforge/findbugs/coreplugin/1.3.2/coreplugin-1.3.2.jar"
excludefilter="findbugs-exclude.xml">
<class location="${build.classes.dir}"/>
<auxClasspath>
<path path="${run.classpath}"/>
</auxClasspath>
<sourcePath path="${src.dir}"/>
</findbugs>
</target>
The above simply invokes the Posted at 03:31PM Sep 19, 2008 by Fabian Ritzmann in Sun | Comments[2] |
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Any reason why you are not using the findbugs-maven-plugin???
Posted by 198.152.12.67 on November 18, 2008 at 12:39 PM EET #
I am not sure I understood the comment. This blog is about using Findbugs from an Ant build script. The Maven plugin would not help. The twist here is that we use Maven to download Findbugs from within the Ant script. Usually, when using Ant, you would check the Findbugs libraries into the workspace but that takes much more space.
Posted by Fabian Ritzmann on November 18, 2008 at 02:21 PM EET #