Hii Everyone, For JDK-17, gradle version = 8.9 Fac...
# community-support
h
Hii Everyone, For JDK-17, gradle version = 8.9 Facing this issue :
Copy code
Cause 1: groovy.lang.MissingPropertyException: Could not get unknown property 'excludeCoverage' for object of type org.gradle.internal.jacoco.rules.JacocoViolationRulesContainerImpl
Cause 2: groovy.lang.MissingPropertyException: Could not get unknown property 'excludeCoverage' for task ':coverageReport' of type org.gradle.testing.jacoco.tasks.JacocoReport
when building the below build.gradle.kts file :
Copy code
plugins {
    java
    checkstyle
    jacoco
    id("brazil-gradle")
    id("brazil-gradle-java-presets")
    id("com.github.spotbugs")
}

brazilGradle {
    configureBasicDependencies()
    configureAnnotationProcessors()
}

val commonBuildConfig = brazilGradle.path("[CommonBuildTools]pkg.runtimefarm")

val excludeCoverage = setOf(
        "**/module/**",
        "**/constants/**",
        "**/models/**",
        "**/enums/**",
        "**/dagger/**",
        "**/*_Factory*",
        "**/builders/CommonBuilder.class"
)
apply(from = "$commonBuildConfig/CommonBuildTools.gradle")


spotbugs {
    ignoreFailures.set(false)
    excludeFilter.set(file("${commonBuildConfig}/spotbugs/spotbugs-exclude-filter.xml"))
}
println(
        "Code coverage report available here: " +
                "file://${brazilGradle.buildDir}/brazil-documentation/coverage/index.html"
)
tasks.withType<Test> {
  useJUnitPlatform()
}
File that is being imported
Copy code
checkstyle {
    sourceSets = [sourceSets.main]
    ignoreFailures = false
    configFile = file("${brazilGradle.path('[CommonBuildTools]pkg.runtimefarm')}/checkstyle/config.xml")
}

task copyTemplate(type: Copy) {
    from "${brazilGradle.path('[CommonBuildTools]pkg.runtimefarm')}/template"
    into project.projectDir
}
build.dependsOn copyTemplate

/*
 Configures the JaCoCo "jacoco" plugin. Remove this if you want to skip
 these checks and report generation.

 Set minimum code coverage to fail build, where 0.01 = 1%.
*/
check.dependsOn jacocoTestCoverageVerification
jacocoTestCoverageVerification {
    violationRules {
        rule {
            limit {
                counter = 'LINE'
                value = 'COVEREDRATIO'
                minimum = 0.99
            }
            limit {
                counter = 'BRANCH'
                value = 'COVEREDRATIO'
                minimum = 1.00
            }
        }
        afterEvaluate {
            classDirectories.setFrom(files(classDirectories.files.collect {
                fileTree(dir: it, exclude: excludeCoverage)
            }))
            println "Code coverage report available here: file://${brazilGradle.buildDir}/brazil-documentation/coverage/index.html"
        }
    }
}
coverageReport {
    afterEvaluate {
        classDirectories.setFrom(files(classDirectories.files.collect {
            fileTree(dir: it, exclude: excludeCoverage)
        }))
    }
}
v
Yeah, welll, the message is quite clear, isn't it? You try to access the property
excludeCoverage
in your bad-practice legacy script plugin twice, but this property does not exist. You only have a local variable in your build script with that name.
h
@Vampire makes sense, but the only thing which I am not able to figure out is, that we have other scripts doing the same exact thing those are not facing this issue, those are build.gradle scripts
v
I bet you are not doing the same (declaring a local variable using
def
) but setting an
ext
/
extra
property in those which most often also is a code smell hinting and doing something not properly but as work-around. 🙂
h
Copy code
def commonBuildConfig = brazilGradle.path('[CommonBuildTools]pkg.runtimefarm')
/*
  Add tests with the defined coverage ratios for line and branch as given in AsdnCapacityCommonBuildTools
  and keep only those files/packages/classes in excludeCoverage for which tests are not added.
*/
excludeCoverage = [
        '**/package-info.java',
        '**/health/**',
]
apply from: "$commonBuildConfig/CommonBuildTools.gradle"

/*
 Configures the SpotBugs "com.github.spotbugs" plugin. Remove this and the
 plugin to skip these checks and report generation.
*/
spotbugs {
    ignoreFailures = false
    excludeFilter.set(file("$commonBuildConfig/spotbugs/spotbugs-exclude-filter.xml"))
}
This is a piece of that script that is using commonBuildConfig
v
Yeah, see, exactly what I said. You are setting an extra property that can be seen by the legacy script plugin. If you would declare a local variable with
def excludeCoverage = ...
you would have the same situation.
🙌 1