I noticed that https://start.spring.io now uses
tasks.named('test') {
useJUnitPlatform()
}
When it used to be
test {
useJUnitPlatform()
}
I was wondering why the change? The second one seems cleaner even on the IDE.
These are both groovy Gradle no Kotlin
This change has been made to declare tasks lazily, see this Gradle page describing the "Configure avoidance" principles : https://docs.gradle.org/current/userguide/task_configuration_avoidance.html
Especialy this part which explains the difference between your two examples ( someTask is test in your case):
Beware of the hidden eager task realization. There are many ways that a task can be configured eagerly. For example, configuring a task using the task name and a DSL block will cause the task to immediately be created when using the Groovy DSL
// Given a task lazily created with tasks.register("someTask") // Some time later, the task is configured using a DSL block someTask { // This causes the task to be created and this configuration to be executed immediately }
Instead use the named() method to acquire a reference to the task and configure it:
tasks.named("someTask") { }
( related commit Spring initializr project : https://github.com/spring-io/initializr/commit/27fc9d40672496c93742f562b13544d9a27cd484 )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With