从 createDebugCoverageReport 任务中排除包

Exclude packages from `createDebugCoverageReport` task

我试图在 运行 createDebugCoverageReport 任务时排除包,但没有成功。我试过这样的解决方案:

而且我尝试编辑任务本身,其中有一个选项可以从覆盖数据中排除包:

出于某种原因 excludes 无法正常工作,所以我使用 includes 进行了修复。这是代码,它将在单个覆盖率报告中组合单元测试和仪器测试。

task codeCoverageReport(type: JacocoReport, dependsOn: ['testDebugUnitTest', 'createDebugCoverageReport']) {
    reports {
        xml.enabled = true
        html.enabled = true
        csv.enabled = true
    }

    def includeFiles = [
            '**/database/**/*.*',
            '**/repository/**/*.*',
            '**/network/worker/*.*',
            '**/util/extensions/*.*'
    ]

    def mainSrc = "${project.projectDir}/src/main/java"

    classDirectories.from =
            fileTree(
                    dir: "$buildDir/intermediates/app_classes/debug",
                    includes: includeFiles
            ) + fileTree(
                    dir: "$buildDir/tmp/kotlin-classes/debug",
                    includes: includeFiles
            )
    sourceDirectories.from = files([mainSrc])
    executionData.from =
            fileTree(dir: "$buildDir", includes: [
                    "jacoco/testDebugUnitTest.exec",
                    "outputs/code_coverage/debugAndroidTest/connected/*coverage.ec"
            ])
}