Findbugs Gradle插件不会导致构建失败

5
我正在尝试在build.gradle文件中使用findbugs插件来使开发人员的个人构建失败,但它没有起作用。尽管该插件创建了报告,但构建不会失败。 我尝试过调整ignoreFailures属性,但也没有成功。
我使用了这个答案How to write a customized gradle task to not to ignore Findbugs violations but fail after the analysis is completed,它有效,但我不喜欢解析报告,感觉像是一个hack。
是否没有简单的方法(类似于'ignoreFailures')可以使用findbugs使Gradle构建失败?是否有其他适合做到这一点的框架?
附上build.gradle文件:
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath "com.bmuschko:gradle-tomcat-plugin:2.1"
    }
}

subprojects {
apply plugin:'java'
apply plugin:'eclipse'


apply plugin: "findbugs"
findbugs {
    reportsDir = file("$project.buildDir/findbugsReports")
    effort = "max"
    reportLevel = "high"
}

build.dependsOn 'check'

sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8

repositories {
    maven { url "http://repo.maven.apache.org/maven2" }
}

dependencies {

    compile group: 'javax.validation', name: 'validation-api', version:'1.1.0.Final'
    compile group: 'org.springframework.security', name: 'spring-security-web', version: "${VERSION_SPRING_SECURITY}"
    compile group: 'org.springframework.security', name: 'spring-security-config', version: "${VERSION_SPRING_SECURITY}"

    // Spring dependency injection container:
    compile (group: 'org.springframework', name: 'spring-context', version:"${VERSION_SPRING}") {
        exclude(module: 'commons-logging')
    }

    compile group: 'javax.inject', name: 'javax.inject', version:'1'
    compile group: 'org.slf4j', name: 'slf4j-api', version:'1.7.10'
    runtime group: 'org.slf4j', name: 'jcl-over-slf4j', version:'1.7.10'
    runtime group: 'org.slf4j', name: 'slf4j-log4j12', version:'1.7.10'
    runtime group: 'org.aspectj', name: 'aspectjrt', version:"${VERSION_ASPECTJ}"
    runtime group: 'org.aspectj', name: 'aspectjweaver', version:"${VERSION_ASPECTJ}"

    testCompile group: 'org.springframework', name: 'spring-test', version:"${VERSION_SPRING}"
    testCompile group: 'junit', name: 'junit', version:'4.12'



    compile group: 'commons-pool', name: 'commons-pool', version:'1.6'

    compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version:'2.5.1'
    compile group: 'com.fasterxml.jackson.module', name: 'jackson-module-mrbean', version:'2.5.1'

}
}

project(':server:application'){
dependencies {

    compile(project(':server:services')) {
        exclude(module: ':server:data-access')
    }
    compile group: 'org.springframework', name: 'spring-webmvc', version:"${VERSION_SPRING}"
    compile project(':server:dto'), project(':server:utils'), project(':server:model')
}
}

Findbugs并未出现任何故障,即使ignoreFailures=false(尽管这是默认设置)。 - Rivi
你能提供一个能够重现问题的例子吗? - Opal
添加了 build.gradle 文件。 - Rivi
好的,但是在哪里可以找到试用的项目呢?看起来 build.gradle 文件本身没有问题。 - Opal
你说的“project to try”是什么意思?所有的子项目(例如server:application等)都是要尝试的项目……如果我理解正确的话…… - Rivi
我是指一个在网页上重现问题的示例项目。它可以是任何东西 :/ 没有重现问题的样本代码,解决问题可能会很棘手。 - Opal
1个回答

3

如果Findbugs发现的问题不是“高优先级”错误,那么它们将不会被报告,因为你已经明确设置了:

reportLevel = "high"

根据Gradle文档,它明确指出:

报告错误的优先级阈值。如果设置为低,则会报告所有错误。如果设置为中(默认值),则会报告中和高优先级的错误。如果设置为高,则只会报告高优先级的错误。

因此,我的建议是在您的findbugs配置中执行以下操作:

ignoreFailures = false
reportLevel = "low"

对我来说这很有效。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接