Harshal Verma
08/14/2024, 12:33 PMCause 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 :
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()
}Harshal Verma
08/14/2024, 12:35 PMcheckstyle {
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)
}))
}
}Vampire
08/14/2024, 1:43 PMexcludeCoverage 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.Harshal Verma
08/14/2024, 1:49 PMVampire
08/14/2024, 1:52 PMdef) 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. 🙂Harshal Verma
08/14/2024, 1:57 PMdef 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"))
}Harshal Verma
08/14/2024, 1:57 PMVampire
08/14/2024, 2:29 PMdef excludeCoverage = ... you would have the same situation.