Maven + FindBugs - 高优先级警告失败

时间:2012-05-17 18:31:21

标签: java maven hudson findbugs

我在一个大型项目中使用Maven和FindBugs。如果FindBugs产生任何优先级错误,我想导致maven构建失败。可以在pom.xml中设置一个简单的参数,以便在错误上失败,但我需要它在高优先级警告时失败。任何建议都会很大!

1 个答案:

答案 0 :(得分:3)

我怀疑你已经知道了findbugs:检查插件可用的目标。 将阈值配置项设置为“高”应该将目标限制为仅在高优先级问题上失败。

以下是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>

在这个片段中,我对以“com.example”开头的包进行了有限的分析,并将阈值设置为“高”,并配置了findbugs:check以在自动化测试之前运行。

触发构建失败的一个示例:

[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] ------------------------------------------------------------------------

另请参阅:http://mojo.codehaus.org/findbugs-maven-plugin/check-mojo.html了解您可以包含的其他配置选项。您可能希望包含xml报告,以便CI服务器可以使用xmlOutput配置捕获它以便轻松报告故障。