FileNotFound Jacoco / Gradle

584 views Asked by At

I have the following setup:

apply plugin: 'jacoco'

jacoco {
    toolVersion = "0.7.1.201405082137"
}

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

and the following task:

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
    }
}

But when executing:

gradle jacocoTestReport --stacktrace --debug --info

I keep getting:

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

But:

clean createStagingDebugCoverageReport --stacktrace

works just fine. I was trying to use a custom task to omit some classes from the coverage report that were unneeded. What am I doing incorrectly for the exec files to not be generated / how can I find where they are in my package? I've looked through the build directory folder and I'm just not finding them.

Thanks in advance!

1

There are 1 answers

0
isuPatches On BEST ANSWER

So it was an .ec file stuffed in /build/outputs/code-coverage/connected/flavors/staging/ and I had to adjust the test to look at '../app/build/intermediates/coverage-instrumented-classes/classes/staging/debug' to generate the report, but I finally have it working...now I have to work on excluding the classes I don't want.

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
    }
}