7

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.

Manikandan
  • 83
  • 7

2 Answers2

4

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>
Mads Hansen
  • 63,927
  • 12
  • 112
  • 147
  • You might want to split FindBugs into two runs, one for warnings that should stop the build, and one for warnings that should not. – Nathan Ryan May 21 '12 at 14:32
  • Also please note that the warningsProperty only seems to be set correctly if "setExeitCode" is set to "true" (which is the default). – olenz Feb 24 '17 at 10:30
2

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?

Community
  • 1
  • 1
Mark O'Connor
  • 76,015
  • 10
  • 139
  • 185