Gradle task for local tomcat deployment

2019-06-11 14:54发布

问题:

I have written a task for deploying war file in my local tomcat instance. I have few issues in it and need help in it.

Following is gradle task-

task deploy (dependsOn: build){
    delete 'D:/softwares/apache-tomcat-9.0.0.M18/apache-tomcat-9.0.0.M18/webapps/ROOT', 'D:/softwares/apache-tomcat-9.0.0.M18/apache-tomcat-9.0.0.M18/webapps/ROOT.war'
    copy {
        from "build/libs"
        into "D:/softwares/apache-tomcat-9.0.0.M18/apache-tomcat-9.0.0.M18/webapps"
        include "ROOT.war"
    }
}

Issue I am facing every time I run deploy task, its updating ROOT.war file but the contents of ROOT directory is not updated

I have checked the timestamps of file to determine which files are updated.

Thanks in advance for help!

回答1:

I had figured in out, I need to wrap the tasks in doLast{} block. So final tasks looks like-

task deploy (dependsOn: build){
  doLast{
    delete 'D:/softwares/apache-tomcat-9.0.0.M18/apache-tomcat-9.0.0.M18/webapps/ROOT', 'D:/softwares/apache-tomcat-9.0.0.M18/apache-tomcat-9.0.0.M18/webapps/ROOT.war'
    copy {
        from "build/libs"
        into "D:/softwares/apache-tomcat-9.0.0.M18/apache-tomcat-9.0.0.M18/webapps"
        include "ROOT.war"
    }
  }
}