Hello all, it there a difference in these two pie...
# community-support
i
Hello all, it there a difference in these two pieces of code:
Copy code
tasks.withType<JavaCompile>().configureEach {
    options.encoding = "UTF-8"
}
and:
Copy code
tasks.withType<JavaCompile>() {
    options.encoding = "UTF-8"
}
(one has .configureEach and the other one not)
v
Yes, the first is good, the second is bad.
It breaks task-configuration avoidance for the tasks in that list as it is an eager API while the `configureEach`works lazy only on the tasks that are going to configured anyway, i.e. usually that they are going to be executed.
👍 2
i
Thanks!
👌 1
c
I feel the need to mention that I'm in favor of them breaking backwards compatibility on this API so that the first and the second do the same thing. It is extremely unintuitive what's lazy and what's eager. The second is a bad API that does the thing you want it to do. The first is a good API that has bad behavior
e
Maybe I'm misremembering, but isn't the keystone feature of Gradle 9 a bytecode rewriter that makes the second example actually be the first?
m
There registration API aren't in scope of rewriting for 9.0, only JavaBean-style eager properties are. But it is a nice idea, the infrastructure can handle that. Unfortunately, this is unlikely to happen in 9, but we'll consider expanding the scope of rewrites for 10.
👍 2
v
Besides that, Gradle 9 is not yet reality, and even if it is, I guess that would only help consumers using Gradle 9, so it would probably still be preferable to just use the right API 🙂