Hi, how can i make all existing build tasks depend...
# kotlin-native
s
Hi, how can i make all existing build tasks depends on a custom one ? thannnks
l
Simply:
Copy code
tasks.all {
    dependsOn(yourTask)
}
It's possible that you need to not make self-dependency though:
Copy code
tasks.all {
    if (this != yourTask) dependsOn(yourTask)
}
s
Got a Circular dependency exception your example use the gradle kotlin dsl ? there is what i've tried:
Copy code
tasks.all {
    if (this.name != "customTask") dependsOn customTask
}
and
Copy code
tasks.all {
    if (this != tasks.getByName("customTask")) dependsOn customTask
}
this != yourTask
does not work because my custom task is of type Exec
l
Using Gradle Kotlin DSL will prevent you from needing
equals
. This should work but keep in mind it's using internal API, so they could change in the future:
Copy code
tasks.all {
    if (this != yourTask && yourTask !in taskDependencies.getDependencies(this)) {
        dependsOn(yourTask)
    }
}
s
ow, i'm sorry it was not clear, i'm not using the kotlin DSL🤐
l
You can probably make it work in Groovy with only a few changes
s
Yes it's ok thank you