How is the order of the doFirst method determined in a gradle build script? I have the following sample script that contains two doFirst methods. I understand that they are additive, as they both execute, but the order that this occurs looks backward:
task initialize
task depTask(dependsOn: initialize)
initialize {
doFirst {
println 'processing doFirst in initialization (configuration)'
}
println 'processing initialize (configuration)'
}
depTask {
println 'processing depTask (configuration)'
}
depTask << {
println 'executing depTask (execution)'
}
initialize << {
println 'executing initialize (execution)'
}
initialize.doFirst {
println 'executing doFirst on initialize (execution)'
}
The output from this script is:
processing initialize (configuration)
processing depTask (configuration)
executing doFirst on initialize (execution)
processing doFirst in initialization (configuration)
executing initialize (execution)
executing depTask (execution)
The first "doFirst" function is defined in the initialize task. The second is defined outside of the configuration block. Why doesn't the first instance execute before the second one? The order of execution looks backward. I would have expected the first one, inside the configuration definition, to execute first. Any help understanding this would be appreciated.
initialize { doFirst { ... } }
and initialize.doFirst { ... }
are the exact same thing. Both statements are inserting an action at the front of the task's action list. Hence the action that gets inserted later (in this case further down in the script) will get executed first.
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