Reputation: 123
I have a task in my build.gradle in subproject dir:
task copyResources {
copy {
from 'cli'
into 'build/cli'
}
copy {
from 'module'
into 'build/module'
}
}
It's purpose is to copy two folders from project dir to Gradle's build folder. But since destination folder is called 'build', execution of other tasks might introduce some weird behaviors (clean, for example).
When I try to move this task to execution phase, it does not run:
Skipping task ':copyResources' as it has no actions.
And from what I know, it's correct behavior, because source and destination of a Copy task have to be set in configuration phase.
Is it possible to postpone execution of this task, so it runs after 'build' task? Or I have to create different task, using some ordinary Java/Groovy code, without using Gradle's copy(), and run it in execution phase only?
Upvotes: 4
Views: 2443
Reputation: 6913
They way you have the task defined, the copy is happening as part of configuration time. If you want to move it into execution time you can wrap it into a doLast
block like below.
task copyResources {
doLast {
copy {
from 'cli'
into 'build/cli'
}
copy {
from 'module'
into 'build/module'
}
}
}
Here are some docs that may help with understanding execution vs configuration time: https://docs.gradle.org/current/userguide/build_lifecycle.html
Upvotes: 8