gpt4 book ai didi

gradle - 单个 Gradle Exec 任务中的多个 bash 命令与每个具有单个命令的多个 Gradle Exec 任务

转载 作者:行者123 更新时间:2023-12-04 04:19:24 30 4
gpt4 key购买 nike

我正在使用 gradle 来自动化 docker 发布和标记。我目前有以下一组任务:

task dockerTagLatest(type: Exec) {
description "Build a Docker image of the current version and tag it as 'latest'"
dependsOn 'docker'
group 'Publishing'

commandLine(['docker', 'tag', dockerImageName, dockerImageLatest])
}

task dockerPush(type: Exec, overwrite: true) {
description 'Push the Docker image of the current version to the internal Docker hub'
group 'Publishing'
mustRunAfter 'dockerTagLatest'

commandLine 'docker', 'push', dockerImageName
}

task dockerPushLatestTag(type: Exec) {
description "Push the 'latest' tag to the internal Docker hub"
group 'Publishing'
mustRunAfter 'dockerTagLatest'

commandLine 'docker', 'push', dockerImageLatest
}

task dockerPublish() {
description "Push the Docker image of the current version and the 'latest' tag to the internal Docker hub"
dependsOn 'dockerTagLatest'
dependsOn 'dockerPush'
dependsOn 'dockerPushLatestTag'
group 'Publishing'
}

有这样的东西会更好吗?
task dockerPublish(type: Exec) {
commandLine 'bash', '-e', '-c', """
docker tag ...
docker push ...
docker push ...
"""
}

显然,第二种方法不是 Windows 友好的,但暂时不管,是拥有一组依赖的 Exec 任务,还是将所有命令行命令集中到一个任务中更好?我收到反馈说后者更具可读性,但我认为第一种方法更像 Gradle。想法?

最佳答案

是否曾经有过您不想按照确切顺序运行所有这些任务的情况?它们中的任何一个都可以通过 future 的 Gradle 功能并行化吗?

如果其中任何一个的答案是"is",那么您可能需要使用单独的任务;否则一项任务就好了。

关于gradle - 单个 Gradle Exec 任务中的多个 bash 命令与每个具有单个命令的多个 Gradle Exec 任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34009417/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com