【发布时间】:2018-08-01 18:52:54
【问题描述】:
首先...我是 Gradle 新手。话虽如此,我喜欢它。不幸的是,我遇到了障碍。我有一系列任务是部署过程的一部分。一个 (buildProject) 调用一个 shell 脚本,作为其进程的一部分,它会使用新的“版本”更新一个 REVISION 文件。之后调用deployToRemote 任务将最新版本部署到服务器。它调用getCurrentVersion 从REVISION 文件中读取最新版本。下面概述了所有这些任务。问题是getLatestVersion 似乎被称为first,尽管有正确的mustRunAfter 语句,因为它总是在REVISION 文件中列出的“PRE”buildProject 版本中读取。我如何确保getLatestVersion 在 buildProject 运行后读取文件?
以下是任务:
构建项目:
task buildProject(type:Exec) {
def command = ['./make-release', '-f']
if (deployEnvironment != 'stage') {
command = ['./make-release', "-e ${deployEnvironment}"]
}
commandLine command
}
部署到远程
task deployToRemote(dependsOn: 'getCurrentVersion') {
doLast {
def version = tasks.getCurrentVersion.hash()
println "Using version ${version}"
println "Using user ${webhostUser}"
println "Using host ${webhostUrl}"
ssh.run {
session(remotes.webhost) {
put from: "dist/project-${version}.tar.gz", into: '/srv/staging/'
execute "cd /srv/staging; ./manual_install.sh ${version}"
}
}
}
}
获取当前版本
task getCurrentVersion {
def line
new File("REVISION").withReader { line = it.readLine() }
ext.hash = {
line
}
}
我的build.gradle 文件末尾有这个:
deployToRemote.mustRunAfter buildProject
getCurrentVersion.mustRunAfter buildProject
REVISION 文件如下所示;
1196.dev10
919b642fd5ca5037a437dac28e2cfac0ea18ceed
dev
【问题讨论】:
标签: file gradle order-of-execution