I have a multi-module gradle project configured with convention plugins. I'd like to be able to exclude classes from the code coverage report both in the convention plugin and in the module level build script.
Here are the relevant files from the project:
buildSrc/src/main/kotlin/mapstruct-conventions.gradle.kts
// ...other configurations here
tasks.jacocoTestReport {
classDirectories.setFrom(
files(
classDirectories.files.map {
fileTree(it).apply {
exclude("**/*MapperImpl*")
}
}
)
)
}
database-jooq/build.gradle.kts
plugins {
id("mapstruct-conventions")
}
tasks.jacocoTestReport {
classDirectories.setFrom(
files(
classDirectories.files.map {
fileTree(it).apply {
exclude("**/jooq/generated/**")
}
}
)
)
}
For some reason the two exclusions seem to override each other. If both are present, then only the one in the convention plugin will be applied. If I remove the exclusion from the convention plugin script, then the exclusion in the database-jooq module works fine.
I tried to define them in an afterEvaluate
block as suggested in some answers but I get the following exception:
Caused by: org.gradle.api.internal.AbstractMutationGuard$IllegalMutationException: Project#afterEvaluate(Action) on project ':database-jooq' cannot be executed in the current context.
Is there a way to define JaCoCo exclusions in different places and apply them together?