FileNotFound Jacoco / Gradle

时间:2015-06-23 12:05:35

标签: android gradle jacoco

我有以下设置:

apply plugin: 'jacoco'

jacoco {
    toolVersion = "0.7.1.201405082137"
}

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

以及以下任务:

task jacocoTestReport(type:JacocoReport, dependsOn: "assembleStagingDebugAndroidTest") {
    group = "Reporting"

    onlyIf = {
        true
    }
    description = "Generate Jacoco coverage reports for staging debug"
    classDirectories = fileTree(
        dir: '../app/build/intermediates/classes/staging/debug',
        excludes: ['**/R.class',
                   '**/R$*.class',
                   '**/*$ViewInjector*.*',
                   '**/*$MembersInjector*.*',
                   '**/BuildConfig.*',
                   '**/Manifest*.*']
   )

   additionalSourceDirs = files(coverageSourceDirs)
   sourceDirectories = files(coverageSourceDirs)
   executionData = files('../app/build/jacoco/testDebug.exc')

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

但执行时:

gradle jacocoTestReport --stacktrace --debug --info

我一直在:

app/build/jacoco/testDebug.exc (No such file or directory)

可是:

clean createStagingDebugCoverageReport --stacktrace

工作得很好。我试图使用自定义任务来省略不需要的覆盖率报告中的某些类。我怎么做错误的exec文件没有生成/我如何找到他们在我的包中的位置?我查看了构建目录文件夹,我只是找不到它们。

提前致谢!

1 个答案:

答案 0 :(得分:0)

所以这是一个填充在/ build / outputs / code-coverage / connected / flavors / staging /中的.ec文件,我不得不调整测试以查看'../app/build/intermediates/coverage-instrumented -classes / classes / staging / debug'来生成报告,但我终于让它工作了......现在我必须努力排除我不想要的类。

task jacocoStagingDebugTestReport(type:JacocoReport, dependsOn: ["spoonStagingDebugAndroidTest"]) {
    group = "Reporting"

    onlyIf = {
        true
    }
    description = "Generate Jacoco coverage reports for staging debug"
    classDirectories = fileTree(
            dir: '../app/build/intermediates/coverage-instrumented-classes/classes/staging/debug',
            excludes: ['/ollie/*$ModelAdapter.*']
    )

    additionalSourceDirs = files(coverageSourceDirs)
    sourceDirectories = files(coverageSourceDirs)
    executionData = files('build/outputs/code-coverage/connected/flavors/staging/coverage.ec')

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