How can I set the minimum code coverage in Jacoco Gradle?
I want the build to fail if it is not met.
The feature is now available. You simply need to apply the Gradle JaCoCo plugin and define coverage verification like this:
apply plugin: 'jacoco'
jacocoTestCoverageVerification {
violationRules {
rule {
limit {
minimum = 0.7
}
}
}
}
// to run coverage verification during the build (and fail when appropriate)
check.dependsOn jacocoTestCoverageVerification
The last line is very important as your build would otherwise not fail unless you explicitly run the jacocoTestCoverageVerification
task.
More information on the kind of checks you may add is in the documentation of the plugin.