Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to copy file in gradle?

Tags:

gradle

groovy

I'm trying to deploy war archive into Tomcat. Here is a build script I've written:

apply plugin : 'war'

task deploy (dependsOn: war){
    copy {
        from "build/libs"
        into "E:/apache-tomcat-8.0.14/webapps"
        include "*.war"
    }
}

But it has no effect. There is no war in the root of webapps. Gradle output:

:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:war
:deploy

What's wrong?

Please don't suggest me any tomcat-cargo plugin in order to do that. I just want to know how to fix that particular file-copying task.

like image 701
St.Antario Avatar asked Nov 08 '14 08:11

St.Antario


1 Answers

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"
}
like image 156
JB Nizet Avatar answered Sep 22 '22 19:09

JB Nizet