【问题标题】:Findbugs & Ant - Stop the build for particular violationFindbugs & Ant - 停止特定违规的构建
【发布时间】:2012-05-21 14:21:19
【问题描述】:

我正在使用 ANT 构建我的应用程序,并且正在检查我的代码是否存在任何 Findbugs 违规。

现在,我的目标是在我的代码包含特定的 findbug 违规时停止构建。

这可以使用 ANT 和 Findbugs 吗?

注意最好不要写入任何自定义类。

【问题讨论】:

    标签: java ant findbugs


    【解决方案1】:

    使用warningsProperty attribute on your findbugs task 为任何警告设置属性:

    <findbugs ... warningsProperty="findbugsFailure"/> 
    

    如果产生警告则失败task

    <fail if="findbugsFailure">
    

    例如:

      <property name="findbugs.home" value="/export/home/daveho/work/findbugs" />
    
      <target name="findbugs" depends="jar">
    
        <findbugs home="${findbugs.home}"
                  output="xml"
                  outputFile="bcel-fb.xml" 
                  warningsProperty="findbugsFailure">
          <auxClasspath path="${basedir}/lib/Regex.jar" />
          <sourcePath path="${basedir}/src/java" />
          <class location="${basedir}/bin/bcel.jar" />
        </findbugs>
    
        <fail if="findbugsFailure">
    
      </target>
    

    【讨论】:

    • 您可能希望将 FindBugs 分成两次运行,一次用于应该停止构建的警告,一次用于不应该停止构建的警告。
    • 另外请注意,只有当“setExeitCode”设置为“true”(这是默认设置)时,warningsProperty 才似乎设置正确。
    【解决方案2】:

    另一种想法(值得付出努力)是将Sonar 集成到您的ANT build 流程中。

    Sonar 集成了 Findbugs(以及 checkstyle 和 PMD),您可以使用它的构建中断插件集中配置它以使构建失败,使其不符合任何标准。见:

    How do I make Hudson/Jenkins fail if Sonar thresholds are breached?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多