【问题标题】:Maven + FindBugs - fail on high-priority warningMaven + FindBugs - 高优先级警告失败
【发布时间】:2012-05-17 18:31:20
【问题描述】:

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

【问题讨论】:

  • 如果发现此类警告,Findbugs 是否会输出一些消息?
  • 是的,他们有。你在想什么?
  • 在我们公司,我们使用 TeamCity 作为我们的 CI 服务器,如果在日志中遇到某些消息,它可以选择失败构建。也许哈德逊也有类似的东西。如果是这样,您可以使用它 =)

标签: java maven hudson findbugs


【解决方案1】:

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

这是你的 pom.xml 的示例配置 sn-p

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

在这个 sn-p 中,我对以 'com.example' 开头的包进行了有限的分析,并将阈值设置为 High,并将 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 配置轻松捕获它以报告故障。

【讨论】:

  • 嗯...这是部分工作。即使只遇到正常的优先级错误,它看起来也失败了。我会检查 check-mojo 文档。
  • 我不明白你的意思......假设我们忘记了 Hudson - 即使我在我的 pom.xml 中运行mvn clean install findbugs:check 上面的内容,在一个只有低优先级警告的项目上,由于 findbugs 导致构建失败。就好像它完全忽略了门槛。
  • 还有一件事:这实际上可能是 Maven 插件中的一个错误(我几乎确信)在这种情况下,解决方法是构建一个过滤器文件,然后尝试使用它(看起来再次在相应选项的 check-mojo 链接上)。 stackoverflow.com/questions/4657336/…
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-08-20
  • 2012-12-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-08-18
相关资源
最近更新 更多