问题
I am using Maven and FindBugs on a large project. I would like to cause a maven build to fail if FindBugs yields any high priority errors. A simple parameter can be set within a pom.xml to fail on errors but I need it to fail on high priority warnings. Any suggestions would be huge!
回答1:
I suspect you are already aware of the findbugs:check goal available for the plugin. Setting the threshold configuration item to High should limit the goal to failing only on High priority issues.
Here is an example configuration snippet for your pom.xml
<build>
...
<plugins>
...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>2.4.0</version>
<executions>
<execution>
<id>failing-on-high</id>
<phase>process-test-resources</phase>
<goals>
<goal>check</goal>
</goals>
<configuration>
<threshold>High</threshold>
<onlyAnalyze>com.example.-</onlyAnalyze>
</configuration>
</execution>
</executions>
</plugin>
...
</plugins>
...
</build>
In this snippet, I have limited analysis to packages beginning with 'com.example' and set the threshold to High, and configured the findbugs:check to run before the automated tests.
An example of this triggering a build failure:
[INFO] --- findbugs-maven-plugin:2.4.0:findbugs (findbugs) @ channels ---
[INFO] Fork Value is true
[java] Warnings generated: 29
[INFO] Done FindBugs Analysis....
[INFO]
[INFO] <<< findbugs-maven-plugin:2.4.0:check (failing-on-high) @ channels <<<
[INFO]
[INFO] --- findbugs-maven-plugin:2.4.0:check (failing-on-high) @ pricing ---
[INFO] BugInstance size is 29
[INFO] Error size is 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
See also: http://mojo.codehaus.org/findbugs-maven-plugin/check-mojo.html for other configuration options you can include. You will probably want to include the xml report so that your CI server can capture it for reporting the failures easily, using the xmlOutput configuration.
来源:https://stackoverflow.com/questions/10641467/maven-findbugs-fail-on-high-priority-warning