将Android Gradle插件从3.1.3升级到3.2.0后,FindBugs停止工作

时间:2018-10-02 12:20:08

标签: android gradle findbugs

我在Android项目中使用FindBugs进行静态代码分析。设置如下:

quality.gradle

plugins.apply('findbugs')

task findbugs(type: FindBugs) {
    ignoreFailures = false
    effort = 'max'
    reportLevel = 'high' // Report only high priority problems.

    classes = files("${project.projectDir}/build/intermediates/classes")
    source = fileTree('src/main/java')

    classpath = files()

    reports {
        xml.enabled = true
        html.enabled = false
    }

    excludeFilter = rootProject.file('quality/findbugs.xml')
} 

build.gradle

subprojects {
    afterEvaluate {
        project.apply from: '../quality/quality.gradle'
        tasks.findByName('findbugs').dependsOn('assemble')
        tasks.findByName('check').dependsOn('findbugs')
    }
}

但是我将Gradle Android插件从3.1.3升级到3.2.0后,构建开始失败:

./gradlew clean build

> Task :app:findbugs FAILED
No files to be analyzed

...

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:findbugs'.
> Failed to run Gradle FindBugs Worker
   > Process 'Gradle FindBugs Worker 6' finished with non-zero exit value 1

降级到3.1.3使构建再次通过。我没有在Gradle Android插件的changelog中找到任何相关内容。有人可以指出插件或设置的问题吗?

1 个答案:

答案 0 :(得分:11)

经过简短的调查,我发现Java类文件的位置已从build/intermediates/classes更改为build/intermediates/javac。新的FindBugs配置:

task findbugs(type: FindBugs) {
    ...
    classes = files("${project.projectDir}/build/intermediates/javac")
   ...
} 

奇怪的是,Android Gradle插件changelog或Gradle changelog中都没有提到这一重大变化。