Reputation: 1526
In Gradle it is easy to define tasks to run after the build.
task finalize1 << {
println('finally1!')
}
build.finalizedBy(finalize1)
This works as expected. But now I want to execute a copy task at the end.
task finalize (type: Copy) {
def zipFile = file('data/xx.zip')
def outputDir = file("data/")
println('Unzip..')
from zipTree(zipFile)
into outputDir
}
build.finalizedBy(finalize)
This does not work anymore. I see the "Unzip" output at the beginning of the build (I need the extract at the end).
Unzip..
:clean
:compileJava
:processResources
:classes
:findMainClass
:jar
:bootRepackage
:assemble
...
<<
does the trick it seems but how I can I merge these two?
Upvotes: 4
Views: 9047
Reputation: 11609
You don't have to. You see Unzip...
at the beginning of the build, but it does not mean that Gradle is executing your task at that moment.
This message is printed in console when Gradle starts to configure your copy task, e.g. adding paths to inputs and outputs. Real execution is done after build. To verify that you can use doLast
closure:
task finalize (type: Copy) {
doLast { println 'running now' }
...
}
Code inside doLast
block will be executed after build.
P.S. Don't move the rest of your task code (from zipTree(zipFile)
, etc) inside doLast
closure, it won't work.
Upvotes: 3