This message was deleted.
# community-support
s
This message was deleted.
c
Noticing a few things, no configureEach on the withType, and an afterEvaluate block
Unfortunately a quick google shows pretty much the above block copy-pasted into multiple answers on stackoverflow
The cleanest I’ve gotten so far is
Copy code
tasks.jacocoTestReport {
    classDirectories.setFrom(
        classDirectories.files.map {
            fileTree(it) {
                exclude(codeCoverageExclusions)
            }
        }
    )
}
but I’m not 100% sure if that’s the best way.
Or perhaps
Copy code
tasks.jacocoTestReport {
    classDirectories.setFrom(
        classDirectories.asFileTree.matching {
            exclude(codeCoverageExclusions)
        }
    )
}
?
v
I don't remember exactly what the problem is and why it needs super-late evaluation, but what I did to prevent using
afterEvaluate
and not depend on the timing problems it adds, is to use a "configure task" like this:
Copy code
val applyJacocoTestReportExcludes by tasks.registering {
    doLast {
        tasks.withType<JacocoReport> {
            classDirectories.setFrom(classDirectories.asFileTree.matching {
                exclude(
                        ...
                )
            }.files)
        }
    }
}

tasks.jacocoTestReport {
    dependsOn(applyJacocoTestReportExcludes)
}

jacocoIntegTestReport {
    dependsOn(applyJacocoTestReportExcludes)
}
But this will only work if you do not need configuration cache compatibility, because configuring tasks from the execution phase of other tasks is not supported with it.
Here is an according issue to watch and thumbs-up: https://github.com/gradle/gradle/issues/13013
So if the files you want to exclude are generated files, it might also be an option to post-process the generated files to add a
Generated
annotation that has
CLASS
retention and not use that hack-around at all.
c
Excellent point! I think this netflix plugin we’re using has an option for adding a generated annotation (including generating a custom one with retention)
v
Then I guess that should be the way to go 🙂