gradle-console-reporter icon indicating copy to clipboard operation
gradle-console-reporter copied to clipboard

./gradlew jacocoTestReport does not print coverage

Open schwaerz opened this issue 1 year ago • 1 comments

I don't know why, but the jacocoTestReport task is the only task which does not print any coverage information. I tried with different configuration settings.

I can use the following workaround (using the settings in my build.gradle as written below):

./gradlew build
./gradlew jacocoTestReport
./gradlew build

Current settings in build.gradle look like:

jacoco {
    toolVersion = "0.8.2"
    // reportsDir = file("$buildDir/customJacocoReportDir")
}

consoleReporter {
    jacoco {
        reportAfterBuildFinished true
        onlyWhenCoverageTaskExecuted false
        reportFile new File("${project.buildDir}/reports/jacoco/test/jacocoTestReport.xml")
        coverageTaskName 'jacocoTestReport'
    }
}

jacocoTestReport {
    dependencies {
        test
    }
    reports {
        xml.enabled true
        csv.enabled false
        html.destination file("${buildDir}/jacocoHtml")
    }
}

jacoco {
    applyTo run
}

task applicationCodeCoverageReport(type:JacocoReport){
    executionData run
    sourceSets sourceSets.main
}
  • The first call to build will show a coverage of 0%, as no report has been generated yet
  • The call to jacocoTestReport will not output any coverage
  • The 2nd call to build will pick up the report as generated by jacocoTestReport and display the coverage:
localuser@localhost:~/repositories/butler$ ./gradlew build
...
Coverage summary:
butler:   0.0%

BUILD SUCCESSFUL in 23s
10 actionable tasks: 10 executed
localuser@localhost:~/repositories/butler$ ./gradlew jacocoTestReport

BUILD SUCCESSFUL in 1s
2 actionable tasks: 1 executed, 1 up-to-date
localuser@localhost:~/repositories/butler$ ./gradlew build

Coverage summary:
butler:  77.5%

BUILD SUCCESSFUL in 729ms
10 actionable tasks: 1 executed, 9 up-to-date
localuser@localhost:~/repositories/butler$ ./gradlew jacocoTestReport

schwaerz avatar May 05 '23 16:05 schwaerz