Reputation: 153
I'm trying to get JaCoCo code coverage reports to be generated whenever ./gradlew test
is run. I've got the following in my build.gradle
file:
apply plugin: "java" // needed by jacoco plugin
apply plugin: "jacoco"
test {
useJUnitPlatform()
}
jacoco {
toolVersion = "0.8.5"
applyTo junitPlatformTest
}
jacocoTestReport {
reports {
xml.enabled true
html.enabled true
html.destination file("${buildDir}/jacoco/jacocoHtml")
}
}
junitPlatformTest {
jacoco {
destinationFile = file("${buildDir}/jacoco/jacocoReport.exec")
}
}
Whenever I run tests, no xml or html reports are generated. However, JaCoCo does generate a junitPlatformTest.exec
file in {buildDir}/jacoco
. How can I get it to generate some xml and html reports too?
Upvotes: 1
Views: 8121
Reputation: 3256
JaCoCo seems to add a few tasks but doesn't automatically attach them as dependencies to the test tasks.
I have following in build.gradle to make the coverage get generated after the test run:
test.finalizedBy jacocoTestReport
You could use dependsOn rather than finalizedBy but dependsOn won't give you coverage if the tests fail.
Upvotes: 1