(Android - Gradle) Jacoco 覆盖范围不排除某些 class 文件

(Android - Gradle) Jacoco coverage not excluding some class files

我正在尝试使用 Gradle 任务为 Android Studio 项目创建 Jacoco 报告。我想从报告中排除一些未经测试的文件,但它们仍然出现在网络报告中。

这是我定义的 Gradle 任务:

apply plugin: 'jacoco'

jacoco {
    // Use this version for upper ones are broken (with Gradle)
    // https://github.com/jacoco/jacoco/issues/288
    toolVersion = "0.7.1.201405082137"
}

def coverageSourceDirs = [
        'src/main/java/....',
]

task createJacocoReport(type: JacocoReport) {
    println ":${project.name}:Generating Jacoco reports"
    group = "Reporting"
    description = "Generate Jacoco coverage reports after running tests."
    reports {
        xml.enabled = true
        xml.destination = "${buildDir}/jacocoReport.xml"
        csv.enabled = true
        csv.destination = "${buildDir}/jacocoReport.csv"
        html.enabled = true
        html.destination = "${buildDir}/jacocoHtml"
    }
    classDirectories = fileTree(dir: './build/intermediates/classes/release',
            excludes: ['**/R$*.class',
                      '**/R.class',
                      '**/android/**/*.class',
                      '**/google/**/*.class',
                      '**/Activities/*.class',
                      '**/Fragments/*.class',
                      '**/Views/*.class',
                      '**/NativeImplementations/*.class',
                      '**/BuildConfig.class',
                      '**/CameraDefaultConfig.class'])

    sourceDirectories = files(coverageSourceDirs)
    executionData = files("./build/jacoco/testReleaseUnitTest.exec")
}

然后我启动这个任务:

check.finalizedBy(createJacocoReport)

有人知道发生了什么事吗?我正在使用 Android Studio 2.1.1 和 Gradle 插件 2.1.0.

谢谢!

我已经解决了这个问题,将排除列表替换为包含列表。虽然我不明白这是什么原因,如果有人有想法...