1
votes

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.

1

1 Answers

3
votes

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.