Hi guys, I'm still confused about the usage of the...
# kotlin-dsl
o
Hi guys, I'm still confused about the usage of the below code. What's the difference between them? Will it cause any potential performance impact? Which one should I use if I only want it to take effect when I want to execute
publish
or
publishToMavenLocal
?
Copy code
tasks.withType<AbstractPublishToMaven> {
    dependsOn(tasks.build)
}

tasks.withType<AbstractPublishToMaven>().configureEach {
    dependsOn(tasks.build)
}

tasks.withType<AbstractPublishToMaven>().all {
    dependsOn(tasks.build)
}
v
the middle
t
First and last are equivalent, and will realize all tasks (instantiate and configure them) whether they're scheduled for execution or not. The second one will only get executed for tasks that are scheduled for execution (or have been realized through other means). So prefer the second one. (you can add prints inside the closures and see which one is called depending on the tasks you run)
☝️ 1
o
Thank you all!
Honestly, I'm hoping to make the first one the same as the second one. Or, let the third one be deprecated to reduce confusion.
v
Unlikely. The first one will probably stay like that for backwards compatibility, as that would a breaking change and one that could be very subtle. And the third one has its valid use-cases.
🥲 1