Search code examples
spring-bootgradlejunitjacoco

jacoco test report configurations from build.gradle file causing build failure


After importing an existing project, gradle build for spring boot is failing in my local. This same project I have been able to build successfully before.

The error in console is:

Build file 'C:\Users\path\ce-paddle-core\build.gradle' line: 223 A problem occurred evaluating root project 'ce-paddle-core'. > Could not find method enabled() for arguments [true] on Report xml of type org.gradle.api.reporting.internal.TaskGeneratedSingleFileReport.

Have uploaded part of my build.gradle file.

Commenting lines 223 & 224 solves the build issue but that then I won't get the test reports.


jacoco {
    toolVersion = jacocoVersion
}
jacocoTestReport {
  reports {
    xml.enabled true   //line 223
    html.enabled true
    html.destination file("${buildDir}/reports/coverage")
  }

  afterEvaluate {
    def excludeSourceDirs = jacocoExcludePackage.split(',')
    getClassDirectories().setFrom(files(classDirectories.files.collect {
      def path =it.getPath()
      fileTree(dir: it).filter {
        def fileDir = it.getParent().replace(path+'/', '').replace('/', '.')
        def fileName = it.getName().replace('.class', '')
        if(!excludeSourceDirs.contains(fileDir) && !excludeSourceDirs.contains(fileDir+'.'+fileName)){
            return it
        }
        }
    }))
  }
}

Adding below args in build.gradle file also didn't help.

tasks.withType(Test) {
    jvmArgs += ["--add-opens", "java.base/java.net=ALL-UNNAMED"]
    jvmArgs += ["--add-opens", "java.base/java.util.concurrent=ALL-UNNAMED"]
    jvmArgs += ["--add-exports", "java.xml/jdk.xml.internal=ALL-UNNAMED"]

}

Solution

  • xml.enabled true //line 223

    line: 223 A problem occurred evaluating root project 'ce-paddle-core'. > Could not find method enabled() for arguments [true] on Report xml of type org.gradle.api.reporting.internal.TaskGeneratedSingleFileReport

    This same project I have been able to build successfully before

    Probably before you were using different Gradle version, because documentation for Gradle 7.1 https://docs.gradle.org/7.1/dsl/org.gradle.api.reporting.Report.html#org.gradle.api.reporting.Report:enabled states that enabled property is deprecated and replaced by required

    Note: This property is deprecated and will be removed in the next major version of Gradle.

    Note: This property has been replaced by required.

    And in the documentation for Gradle 8.0 there is required property, but no enabled property anymore - https://docs.gradle.org/8.0/dsl/org.gradle.api.reporting.Report.html#org.gradle.api.reporting.Report:enabled

    Also see updated example of configuration in https://docs.gradle.org/current/userguide/jacoco_plugin.html

    jacocoTestReport {
        reports {
            xml.required = false
            csv.required = false