How to copy file in gradle?
The code inside your task runs during the configuration phase, instead of running during the execution phase. It thus runs before the war task has done anything. The task should look like
task deploy (dependsOn: war) << {
...
}
or
task deploy (dependsOn: war) {
doLast {
...
}
}
Or, even better, instead of defining a task which does a copy in an imperative way when executed, you should make your task a Copy task, and configure it:
task deploy (dependsOn: war, type: Copy) {
from "build/libs"
into "E:/apache-tomcat-8.0.14/webapps"
include "*.war"
}
If you need to copy to from a single source to multiple destinations, you can also try something like this:
task deploy (dependsOn: war, type: Copy) {
// define your multiple directories
def multipleDest = ["$buildDir/libs/folder1", "$buildDir/libs/folder2", "$buildDir/libs/folder3"]
// get the output dirs
multipleDest.each { outputDir ->
outputs.dir outputDir
}
// copy to all of them
doLast {
multipleDest.each { outputDir ->
copy {
from "$buildDir/*.war"
into outputDir
}
}
}
}