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

9 java hudson findbugs maven

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

ste*_*lle 3

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

这是 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>
Run Code Online (Sandbox Code Playgroud)

在此代码片段中,我对以“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] ------------------------------------------------------------------------
Run Code Online (Sandbox Code Playgroud)

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