I have added Detekt to my Gradle project. My intention was to invoke detekt
on demand only, since it creates a lot of false positives. However, the detekt
task is active by default (and breaks the build). How can I avoid this dependency?
What I tried: I have added a gradle.taskGraph.beforeTask
block that sets enabled = false
conditionally:
gradle.taskGraph.beforeTask {
val containsDetektTaskCall = gradle.startParameter.taskNames.contains("detekt")
if (name.startsWith("detekt") && !containsDetektTaskCall) {
logger.lifecycle("Skipping all 'detekt-plugin' tasks")
enabled = false
}
}
I have the feeling that these 7 lines of code are really a bit much just to override a task dependency. I would appreciate a general Gradle answer as well as some Detekt-specific way.