【发布时间】:2014-02-11 23:43:54
【问题描述】:
我试图在我的build.gradle 文件中包含多个 Gradle 任务,以将战争部署到不同的环境。在生成war文件后,我希望能够拥有deployToLocal任务以及deployToQA和deployToDev。
当然,这意味着我要停止Tomcat服务,删除Tomcat webapps目录下已有的war文件和展开的wars,复制war,然后再次重启Tomcat部署服务。
我的问题有两个:
- 我已经指定了我将要复制的战争的位置 连同所有主机名、端口和用户名/密码 信息。我的问题是:如何指定 远程环境(目录结构)战争应该被复制 进入?
- 对于我想要达到的目标,这是前进的正确方式吗?
到目前为止我的代码:
task deleteDirLocalhost(type: Delete){
//delete fileTree(dir: local_Tomcat_webapps_dir)
delete fileTree(dir: 'C:\\Tomcat7.0\\webapps')
}
task deployToLocal{
dependsOn war, tomcatStop, deleteDirLocalhost
println "Starting Cargo"
println "Using war from: $warLocation" // warLocation is a variable defined in gradle.properties file
cargo {
containerId = 'tomcat7x'
port = TomcatPortLocalhost as Integer
local {
homeDir = file(local_Tomcat_webapps_dir) // local_Tomcat_webapps_dir is a variable defined in gradle.properties file
}
deployable {
file = file(warLocation) // This is where I specify where the war file is to be copied from. In the 'local' section, I have specified 'homeDir' as the location where I want this file to be copied to. Is that correct usage?
context = 'web-application'
}
}
tomcatRunWar
}
task deployToQA{
dependsOn war, tomcatStop, deleteDirQA
println "Starting Cargo"
println "Using war from: $warLocation"
cargo {
containerId = 'tomcat7x'
port = TomcatPortQA as Integer
remote {
hostname = server_address_qa // all these are variables defined in the gradle.properties file
username = username_qa
password = password_qa
}
deployable {
file = file(warLocation) // This is where I specify the location of the war file. How do I specify in the 'remote' section in which directory in the server this file should be copied to?
context = 'web-application'
}
}
tomcatRunWar
}
task deployToDev{
dependsOn war, tomcatStop, deleteDirDev
println "Starting Cargo"
println "Using war from: $warLocation"
cargo {
containerId = 'tomcat7x'
port = TomcatPortDev as Integer
remote {
hostname = RT3_webapp_address_dev
username = username_dev
password = password_dev
}
deployable {
file = file(warLocation)
context = 'web-application'
}
}
tomcatRunWar
}
我想调用任务 gradle deployToLocal 并期望本地 Tomcat 实例停止的行为,战争被复制到我的 Tomcat\webapps 文件夹(同一个文件夹中的任何先前存在的文件或文件夹都已被删除),并且然后再次启动Tomcat服务并部署war。
这不起作用,显然我错过了一些东西。我还在网上搜索了一个完整的、完整的 gradle cargo/tomcat 插件实现示例,但运气不佳。有人可以指出我正确的方向吗?
提前感谢您的帮助!
【问题讨论】:
标签: tomcat deployment gradle cargo build.gradle