I'm a little hazy... in the Kotlin DSL, should I u...
# community-support
r
I'm a little hazy... in the Kotlin DSL, should I use:
Copy code
tasks.taskName {
  ...
}
or should I be using
Copy code
tasks.taskName.configure {
  ....
}
In the same vein, is this OK:
Copy code
tasks.withType<KotlinCompile> {
  compilerOptions.jvmTarget = JVM_21
}
or should it be
Copy code
tasks.withType<KotlinCompile>().configureEach {
  compilerOptions.jvmTarget = JVM_21
}
j
Bot are the same (you can check it by yourself if the returned type is the same):
Copy code
tasks.taskName {
  ...
}
Copy code
tasks.taskName.configure {
  ....
}
You should always use
configureEach
. As you can see, both returns different types, and the one without
configureEach
provokes that you need to register the tasks eagerly.
👆 1
I hope with Gradle 9 everything that is not lazy is deprecated, so you get a warning if you don't use
configureEach
.
r
Cool, thanks!
v
I somehow doubt that the eager APIs are deprecated, because there are valid use-cases for them, even if rare. But we will see. :-)