https://kotlinlang.org logo
#detekt
Title
# detekt
g

gavvvr

10/21/2021, 2:31 PM
Hello #detekt community. A question for Gradle users. I just posted it here, on GitHub discussions https://github.com/detekt/detekt/discussions/4196. How do you decouple a failing detekt task from
gradle build
task graph? I am not ready to fix all my existing code base right now to make this step pass. I would like to exclude it from gradle build and run on demand only, by calling it explicitly with
gradle detekt
e

Endre Deak

10/21/2021, 4:11 PM
gradle build -x detekt
would skip detekt
j

Javier

10/21/2021, 4:23 PM
What about providing a baseline file?
b

Brais Gabin

10/21/2021, 5:20 PM
Agree, I think that the baseline is the perfect fit for your requirements. This way you just spot the new issues meanwhile you can remove the old ones slowly.
🤔 1
g

gavvvr

10/21/2021, 9:49 PM
@Endre Deak, on GitHub I said that it’s not an option. Baseline is a good idea, but I haven’t yet decided what rules I would like to use. So weird that I don’t see an easy way to exclude some intermediate task from tasks graph. In Maven it’s usually a user’s responsibility to tie particular task to Maven phases
e

Endre Deak

10/21/2021, 9:57 PM
sorry I haven’t read it through
how about something like
Copy code
tasks.withType<DefaultTask> {
    tasks.getByName("detekt").enabled = false
}
e

ephemient

10/22/2021, 3:37 PM
if you applied the plugin normally, the kotlin dsl will provide a generated accessor
Copy code
tasks.detekt { enabled = false }
or you can disable all detekt tasks
Copy code
tasks.withType<Detekt>().configureEach { enabled = false }
if you just want to disable it when running
check
, that can be done conditionally, e.g.
Copy code
gradle.taskGraph.whenReady {
    if (hasTask("check")) {
        tasks.detekt { enabled = false }
    }
}
👍 1
🤔 1
g

gavvvr

10/27/2021, 9:16 PM
Hi @ephemient. Thanks for the
tasks.detekt { enabled = false }
part! I would like to disable it not on
check
, but in any case unless
detekt
task name is explicitly provided to gradle as an argument. I have a solution on my original GitHub discussion (
if (!("detekt" in gradle.startParameter.taskNames)) {tasks.detekt { enabled = false }}
), but it probably looks ugly
e

ephemient

10/27/2021, 9:21 PM
that works, although at that point I feel you may as well
Copy code
plugins {
    id("detekt") apply false
}
tasks.register<Detekt>("detekt") {
    ...
}
if you don't want anything wired up by default
👍 1
3 Views