我在Mac Yosemite上使用Gradle 2.7。在构建我的WAR时,假设所有测试都通过并且战争的组装成功,我想将我的WAR复制到我的本地$CATALINA_HOME/wbeapps
目录。所以我在我的build.gradle
脚本中定义了这个:
task deployToTomcat(type: Copy) {
from war.archivePath
into "$System.env.CATALINA_HOME/webapps"
}
build.dependsOn deployToTomcat
当我运行gradle build
时,我可以看到任务已运行,但我的$CATALINA_HOME/webapps
目录中没有任何内容。这是输出:
davea$ gradle build
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:war UP-TO-DATE
:assemble UP-TO-DATE
:compileTestJava UP-TO-DATE
:processTestResources UP-TO-DATE
:update
liquibase-plugin: Running the 'main' activity...
INFO 10/28/15 2:11 PM: liquibase: Successfully acquired change log lock
INFO 10/28/15 2:11 PM: liquibase: Reading from cbc_db.DATABASECHANGELOG
INFO 10/28/15 2:11 PM: liquibase: Successfully released change log lock
Liquibase Update Successful
liquibase-plugin: Running the 'test' activity...
INFO 10/28/15 2:11 PM: liquibase: Successfully acquired change log lock
INFO 10/28/15 2:11 PM: liquibase: Reading from PUBLIC.DATABASECHANGELOG
INFO 10/28/15 2:11 PM: liquibase: Successfully released change log lock
Liquibase Update Successful
:testClasses
:test UP-TO-DATE
:check UP-TO-DATE
:deployToTomcat UP-TO-DATE
:build UP-TO-DATE
“UP-TO-DATE”是否表示它已经运行?如何强制执行任务?
编辑:在回答给出的答案时,我改变了我的任务。 WAR文件被复制到名为" null / webapps"的文件夹中。与我的" build.gradle"在同一目录中文件。这是输出
davea$ echo $CATALINA_HOME
/opt/apache-tomcat-6.0.44
davea$ gradle build
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:war UP-TO-DATE
:deployToTomcat UP-TO-DATE
:assemble UP-TO-DATE
:compileTestJava UP-TO-DATE
:processTestResources UP-TO-DATE
:update
liquibase-plugin: Running the 'main' activity...
INFO 10/29/15 9:09 AM: liquibase: Successfully acquired change log lock
INFO 10/29/15 9:09 AM: liquibase: Reading from cbc_db.DATABASECHANGELOG
INFO 10/29/15 9:09 AM: liquibase: Successfully released change log lock
Liquibase Update Successful
liquibase-plugin: Running the 'test' activity...
INFO 10/29/15 9:09 AM: liquibase: Successfully acquired change log lock
INFO 10/29/15 9:09 AM: liquibase: Reading from PUBLIC.DATABASECHANGELOG
INFO 10/29/15 9:09 AM: liquibase: Successfully released change log lock
Liquibase Update Successful
:testClasses
:test UP-TO-DATE
:check UP-TO-DATE
:build UP-TO-DATE
BUILD SUCCESSFUL
Total time: 0.865 secs
答案 0 :(得分:1)
没有必要强制执行任务。相反,请适当配置任务:
task deployToTomcat(type: Copy) {
from war.outputs
into "$System.env.CATALINA_HOME/webapps"
}
war.finalizedBy deployToTomcat
archivePath
定义战争的路径,但要获得使用任务outputs
属性所需的战争。
finalizedBy
在完成任务后始终运行给定任务。在这种特殊情况下,这可以保证正在构建的工件。
UP-TO-DATE
表示该任务未运行。它没有任何关系。