One of the new features of Gradle 1.6, the Groovy based build tool, is Jacoco support. Jacoco is one of the few (only?) Open Source code coverage tools still in active development, and starting from Gradle 1.6, it’s now a supported plugin. Enabling the task is easy, just add
apply plugin: 'jacoco'
to your build.gradle, and run
./gradlew jacocoTestReport and it.. does nothing. For those running into the same issues, this might save you a bit of time:
After a bit of searching, it turns out the Jacoco plugin is a bit broken. When using it with a Java project, as I’m doing, you need to do a couple of things to enable it, but also then, it unfortunately doesn’t work as advertised, though the fix seems not to complex.
First, you need to enable the following:
group = "Reporting"
description = "Generate Jacoco coverage reports after running tests."
additionalSourceDirs = files(sourceSets.main.allJava.srcDirs)
And then, instead of running
./gradlew jacocoTestReport as mentioned in the docs here, you need to run
./gradlew test jacocoTestReport. Unfortunately, no location is printed where the documentation is created, so no clickable links in your terminal, but you can find it under
build/reports/jacoco/test/html/index.html. Well, that wasn’t so bad now, was it? Have fun!
For more information about using Jacoco and Gradle, you can checkout the following resources: