Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Findbugs & Ant - Stop the build for particular violation

Tags:

java

ant

findbugs

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.

like image 754
Manikandan Avatar asked May 21 '12 14:05

Manikandan


People also ask

Is FindBugs a coding standard tool?

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.

What is the difference between FindBugs and SpotBugs?

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.

What is FindBugs in Maven?

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.

What is com Google code FindBugs?

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.


2 Answers

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>
like image 100
Mads Hansen Avatar answered Sep 25 '22 06:09

Mads Hansen


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?

like image 27
Mark O'Connor Avatar answered Sep 22 '22 06:09

Mark O'Connor