This message was deleted.
# community-support
s
This message was deleted.
e
I have a multi-project build which adds detekt to each project using a convention plugin.
Copy code
// in build-logic/**/base-conventions.gradle.kts

plugins {
   id("io.gitlab.arturbosch.detekt")
}

// tried adding this here
tasks.findByName("check")?.run {
   dependsOn.removeIf { (it as? Task)?.name == "detekt" }
   dependsOn(tasks.named("detektMain"))
   dependsOn(tasks.named("detektTest"))
}
I also tried to configure
check
from the root project
Copy code
// ./build.gradle.kts

tasks.named("check").configure {
   dependsOn.removeIf { (it as? Task)?.name == "detekt" }
}
Neither approach worked so far
v
You probably need to use
tasks.check { setDependsOn(...) }
e
Thanks, trying that!
Hmm.. still no luck. Perhaps its not added directly to check, but to some other task run by check. I'll try to print the task graph or something. šŸ™‚
Casting to
Task
was wrong. Shouldve been
TaskProvider
v
•
DetektPlugin#apply
directly unconditionally calls
project._registerDetektPlainTask_(extension)
•
project._registerDetektPlainTask_(extension)
directly unconditionally calls
DetektPlain#registerTasks(extension)
•
DetektPlain#registerTasks(extension)
directly unconditionally calls
project._registerDetektTask_(extension)
•
project._registerDetektTask_(extension)
directly unconditionally calls
tasks.matching { it.name == LifecycleBasePlugin.CHECK_TASK_NAME }.configureEach { it.dependsOn(detektTaskProvider) }
So it is indeed
check
which depends on
detekt
. And the dependency should already be there.
e
ended up with
Copy code
tasks.named("check").configure {
   this.setDependsOn(
      this.dependsOn.filterNot {
         it is TaskProvider<*> && it.name == "detekt"
      } + tasks.named("detektMain") + tasks.named("detektTest"),
   )
}
which is working now šŸ™‚
v
If you don't want to ever execute
detekt
you could also simply disable it šŸ™‚
e
is it better to use
tasks.matching { it.name == LifecycleBasePlugin.CHECK_TASK_NAME }.configureEach
over
tasks.named("check")
?
v
No. If you know the task is there, use
named
named
fails if the task is not there,
matching
just ignores.
āœ… 1
e
I want check to run another task than the default one šŸ™‚ so I cant remove it completely.
v
While actually
tasks.matching
like that should heavily disturb task-configuration avoidance
I wonder right now why it does not
I want check to run another task than the default one šŸ™‚ so I cant remove it completely.
?
e
another than the default
detekt
, I want to use
detektMain
and
detektTest
instead šŸ™‚
v
I got that, but I don't understand that as answer to my suggestion
Copy code
tasks.detekt { enabled = false }
tasks.check { dependsOn(tasks.detektMain, tasks.detektTest) }
Btw. while in Kotlin DSL, you don't need
named
, you can just use the accessors which internally use
named
. Just in Groovy DSL you should use
named
instead to maintain task-configuration avoidance.
e
Oh.. that seems a bit more convenient. šŸ™‚
v
That's what I meant, if you don't intend to call
detekt
at all, not even manually
e
Correct. I dont intend to do that šŸ‘ Thanks a lot. That ended up way better than what I was about to push šŸ’Æ
šŸ‘Œ 1