I want to make jacoco plugin to fail when test coverage is not enough. I use example from gradle page : https://docs.gradle.org/current/userguide/jacoco_plugin.html
apply plugin: 'jacoco'
jacoco {
toolVersion = "0.7.6.201602180812"
reportsDir = file("output/jacoco/customJacocoReportDir")
}
jacocoTestReport {
reports {
xml.enabled false
csv.enabled false
html.enabled true
html.destination file("output/jacoco/jacocoHtml")
}
}
jacocoTestCoverageVerification {
violationRules {
rule {
limit {
minimum = 0.5
}
}
rule {
enabled = false
element = 'CLASS'
includes = ['org.gradle.*']
limit {
counter = 'LINE'
value = 'TOTALCOUNT'
maximum = 0.3
}
}
}
}
However, I get error:
Could not find method jacocoTestCoverageVerification() for arguments [build_4v41fim1xdl76q49oxk7mnylv$_run_closure6@18601994] on root project 'demo' of type org.gradle.api.Project.
Can anyone advise?
According to the the docs for Gradle version 3.4 or higher :
For projects that also apply the Java Plugin, The JaCoCo plugin automatically adds the following tasks:
jacocoTestReport [...]
jacocoTestCoverageVerification [...]
If the code block in your question shows your full build.gradle
file, this would mean that you need to add the line that applies the Java Plugin (apply plugin: 'java'
).
Of course, you could also add a task of type JacocoCoverageVerification
called jacocoTestCoverageVerification
to your build file on your own:
task jacocoTestCoverageVerification(type: JacocoCoverageVerification) {
// configuration
}
Try using latest version of gradle. This may solve your problem
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With