Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not find method jacocoTestCoverageVerification()

Tags:

gradle

jacoco

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?

like image 255
Jacob Avatar asked Sep 03 '17 11:09

Jacob


2 Answers

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
}
like image 164
Lukas Körfer Avatar answered Oct 06 '22 18:10

Lukas Körfer


Try using latest version of gradle. This may solve your problem

like image 27
Ajeesh Avatar answered Oct 06 '22 19:10

Ajeesh