I'm currently studying gradle.
I have the following code
task simpleCopy(type: Copy){
from 'source.xml'
into 'destinationFolder'
}
My understanding is that the code inside {}
is the configuration closure, and it is executed during the configuration phase, to prepare the task for execution during execution phase. So I'm expecting the source.xml
to be copied into destinationFolder
during the configuration phase (in other words, the copying will happen when I simply run gradle
, and I dont have to specifically run gradle simpleCopy
for the copying behavior to happen).
But what I have found is that the copying does NOT happen when I run gradle
at command line. The copying only happens when I explicitly execute the simpleTask
task (i.e. by running gradle simpleTask
at command line). So the code above actually behave the same as
task simpleCopy(type: Copy){
doLast {
from 'source.xml'
into 'destinationFolder'
}
}
Is my understanding of configuration phase and configuration closure incorrect? Or am I missing some information?