How to get jacoco code coverage report in gradle project
Option 1
Run gradle build jacocoTestReport
to generate JaCoCo code coverage report.
Option 2.1
Make tasks dependent in your Gradle scripts:
build.dependsOn jacocoTestReport
and then just run gradle build
. JaCoCo report will be generated at each build
task execution.
Option 2.2 (proposed by Filip Malczak)
Add to your Gradle scripts:
test.doLast jacocoTestReport.&execute
It works in similar fashion as the previous option, but generates report after every execution of test
task. It can be useful if you tend to work by running test
instead of build
.
learn groovy
Updated on June 04, 2022Comments
-
learn groovy almost 2 years
I'm new to Groovy gradle world, I've written small groovy project with all test cases. I'm trying to generate code coverage report using jacoco plugin. But it generates only test report not code coverage report. Please find my jacoco gradle file config. I'm using gradle 4.5 version and Groovy Version: 2.5.0-rc-2 JVM: 1.8.0_171 Vendor: Oracle Corporation OS: Windows 10
What I'm missing here in order to generate jacoco code coverage report in html format.
Appreciated your help in advance!
My jacoco.gradle
apply plugin: "jacoco" jacoco { toolVersion = '0.8.1' } jacocoTestReport { group = "reporting" description = "Generate Jacoco coverage reports after running tests." reports { xml.enabled true html.enabled true csv.enabled false html.destination "${buildDir}/jacocoHtml" } sourceDirectories = fileTree(dir: 'src/main/myproject') }
I'm running
gradle clean build
command to generate build folder under my project repository. -
Filip Malczak almost 6 yearsAlternatively to option #2 - add
test.doLast jacocoTestReport.&execute
- works in similiar fashion, but generates report after every execution oftest
. Can be useful if you tend to work by runningtest
instead ofbuild
and I personally prefer it. @VaL - feel free to edit your answer and add it, this is still your answer, I'm just suggesting. -
62mkv about 4 yearsthis last option does not work for me with "> No signature of method: org.gradle.testing.jacoco.tasks.JacocoReport_Decorated.execute() is applicable for argument types: () values: [] "