The
build.gradle
task hello (type: Copy) {
doLast {
println "print from within"
}
println "print from outside"
}
when run
gradle -q hello
the doLast{} closure is not even touched. change doLast to doFirst, I get the same result:
D:\>gradle -q hello
print from outside
without the doLast or doFirst:
task hello (type: Copy) {
//doLast{
println "print from within"
//}
println "print from outside"
}
it works fine:
D:\>gradle -q hello
print from within
print from outside
This seems happening only with tasks of type Copy. can you please help clarifying? I am using gradle 2.4.
I thought it would be helpful for the people who come to this place on the same question. Though the above explanation is conceptually making sense. There is no proper solution mentioned in the answer. Here is the solution on how i achieved Copy
task with doLast
execution.
task hello () {
doLast{
copy {
println "print from within"
}
}
println "print from outside"
}
This would provide the execution of copy task along with doLast.
$ gradle -q hello
print from outside
print from within
Hope this is useful.
If you run the task without -q
switch you'll notice that the task is already marked as UP-TO-DATE
- which means that no actions (and you add an action via doLast
) were executed.
Why is that? In this particular example, you have configured no inputs and outputs for the task. Copy
tasks resolve it's being up-to-date base on the inputs and outputs and since none were configured Gradle assumes there's no need for it to be run.
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