I am building my application using ANT and I am checking my code for any Findbugs violations.
Now, my objective is to stop the build whenever my code contains particular findbug violation.
Is this possible using ANT & Findbugs?
N.B. Preferably not to write to any custom class.
FindBugs: A Specialized Bug KillerFindBugs is not concerned by formatting or coding standards and only marginally interested in best practices: in fact, it concentrates on detecting potential bugs and performance issues.
SpotBugs is a program which uses static analysis to look for bugs in Java code. It is free software, distributed under the terms of the GNU Lesser General Public License. SpotBugs is a fork of FindBugs (which is now an abandoned project), carrying on from the point where it left off with support of its community.
FindBugs is a static code analysis tool which identifies problems found from Java code. We can integrate FindBugs into our build process by using the FindBugs Maven plugin. This blog post identifies four typical use cases and describes how we can configure the FindBugs Maven plugin to support each use case.
FindBugs is a defect detection tool for Java that uses static analysis to look for more than 200 bug patterns, such as null pointer dereferences, infinite recursive loops, bad uses of the Java libraries and deadlocks.
Use the warningsProperty attribute on your findbugs task to set a property for any warnings:
<findbugs ... warningsProperty="findbugsFailure"/>
and fail task
if warnings are produced:
<fail if="findbugsFailure">
For example:
<property name="findbugs.home" value="/export/home/daveho/work/findbugs" />
<target name="findbugs" depends="jar">
<findbugs home="${findbugs.home}"
output="xml"
outputFile="bcel-fb.xml"
warningsProperty="findbugsFailure">
<auxClasspath path="${basedir}/lib/Regex.jar" />
<sourcePath path="${basedir}/src/java" />
<class location="${basedir}/bin/bcel.jar" />
</findbugs>
<fail if="findbugsFailure">
</target>
An alternative idea (and worth the effort) would be to integrate Sonar into your ANT build process.
Sonar integrates Findbugs (and checkstyle and PMD) and you can centrally configure it to fail the build against any set of criteria using it's build breaker plugin. See:
How do I make Hudson/Jenkins fail if Sonar thresholds are breached?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With