Maven + FindBugs - fail on high-priority warning

↘锁芯ラ 提交于 2019-12-12 10:34:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!