Ahmed Riyadh
05/16/2024, 3:25 PMproject.afterEvaluate {
tasks.check {
dependsOn -= tasks.find {
it.name.equals("checkLicenses")
}
}
}
using it directly in Gradle Kotlin DSL would work without any changes but I updated it to the following to get the type saftey feature of Gradle Kotlin DSL:
project.afterEvaluate {
tasks.check {
dependsOn -= tasks.find { it.name == tasks.checkLicenses.name }
}
}
I'm getting build failure once using any of the code snippets above:
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':build'.
> Could not create task ':check'.
> Removing a task dependency from a task instance is not supported.
And this wasn't an issue in Gradle Groovy, I'm wondering if Gradle Kotlin doesn't allow removing a task dependency and Gradle Groovy does or Gradle Groovy won't throw that error but still unsupported (won't take any affect)Vampire
05/16/2024, 3:40 PMtasks.check { ... }
in Groovy DSL is eager API, while tasks.check { ... }
in Kotlin DSL is lazy API, as tasks.check
in Groovy gives you the task instance while in Kotlin DSL gives you the task provider.Vampire
05/16/2024, 3:41 PMafterEvaluate
is almost always a bad idea.
And removing declared task dependencies is maybe not the best idea either.
But it might work if you use setDependsOn(...)
maybe.Vampire
05/16/2024, 3:42 PM