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

Jacoco coverage reported as 0.0% on first run

Open ardevd opened this issue 6 years ago • 6 comments

It seems like the console reported always prints out 0.0% coverage on the first run in a clean environment.

Steps to produce:

  1. Delete any previous reports directory.
  2. Run ./gradlew jacocoTestReport
  3. Notice how the coverage summary says 0.0% coverage.
  4. Run ./gradlew jacocoTestReport again
  5. The correct coverage summary is now printed.

This makes it impossible to use it for CI integration as the tests there will always be run in a clean environment.

ardevd avatar Mar 23 '18 09:03 ardevd

I worked around this with jacocoTestReport.dependsOn build

To be fair, it seems like more of a jacoco plugin issue than a problem with this plugin.

louth avatar Apr 30 '18 07:04 louth

Unfortunately, your workaround did not solve this issue for me. So in my CI loop I'm actually running the gradle command twice. Fortunately, gradle manages to short-circuit the whole compiling and running of the tests so the build time impact is minimal, but the build config looks very ugly instead.

StFS avatar Oct 22 '19 17:10 StFS

What actually fixed it for me was to add the following line to my build.gradle:

reportCoverage.dependsOn jacocoTestReport

StFS avatar Oct 23 '19 15:10 StFS

Fior me this worked:

test.finalizedBy jacocoTestReport
jacocoTestReport.finalizedBy reportCoverage

PS: I never used gradle before this so do not take this as the "best way" to do this nor anything. Hopefully, it will make someone's day easier.

leonardotc avatar Mar 03 '20 16:03 leonardotc

@ardevd, do you still have this issue or did you find something that worked for you? I face the same issue in a multi-module Gradle project. Thanks.

abedurftig avatar Apr 21 '20 17:04 abedurftig

Never figured out a way around the issue, no.

ardevd avatar Apr 21 '20 17:04 ardevd