This is my last question (at least for now) In th...
# gradle
a
This is my last question (at least for now) In the process of migrating from Gradle Groovy to Gradle Kotlin DSL of a open-source project (I'm sending a PR and I'm almost finish) I found this code:
Copy code
project.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:
Copy code
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:
Copy code
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)
v
It's probably more that
tasks.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.
K 1
But the snippet is extremely questionable actually.
afterEvaluate
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.
👍 1
Also, this snippet completely breaks task-configuration avoidance, most probably cumulated costing much more time than is saved by not always doing the license check.
👍 1