gpt4 book ai didi

gradle - 按顺序对子项目执行gradle任务

转载 作者:行者123 更新时间:2023-12-03 03:48:03 25 4
gpt4 key购买 nike

我们有一个这样的项目结构

ParentProject
projA
projB
projC
projD
...

我们在父项目的这些项目上运行了许多任务,调用 gradle clean build make tag push remove
clean: removes the build directory for each projectbuild: compiles the source codemake: uses the compiled code to create a docker image (custom task)tag: tags the docker image (custom task)push: pushes the tagged docker image to our nexus repo (custom task)remove: removes the local docker image (custom task)

all the tasks work as intended, but not exactly in the order we want.

our issue is disk space. creating all the docker images (we have many to make) takes several gigabytes of space. Gradle fails because it runs out of disk space before reaching the end. We thought we could solve this issue by simply removing the image after it is pushed and free the disk space, but the way gradle runs, that does not work.

Current, gradle executes in the following manner:

projA:clean
projB:clean
projC:clean
...
projA:build
projB:build
projC:build
...
projA:make
projB:make
projC:make
...

经历这样的事情,一切都试图在移除任何东西之前进行构建。我们希望运行gradle的方式如下:
projA:clean
projA:build
projA:make
projA:tag
projA:push
projA:remove
projB:clean
projB:build
projB:make
projB:tag
projB:push
projB:remove
...

这样,在下一个项目开始构建之前,该项目会清理自身并释放磁盘空间。

有什么办法吗?

编辑:有时可能并非每个任务都需要运行。该图像可能已经生成,仅需要重新标记。或可能需要为本地测试而构建,但不加标签或推送。

最佳答案

任务maketagpushremove看起来是自定义任务。

如果您想要任务之间的依赖关系,例如taskX应该在taskY启动时执行,那么您应该使用task的dependsOn属性,也称为任务依赖关系。

下面显示了projA的build.gradle任务取决于projA的make任务的父项目上的clean。您应该对projA的其余任务执行此操作。

project('projA') {
task make(dependsOn: ':projA:build') {
doLast {
println 'make'
}
}
}

project('projA') {
task build {
doLast {
println 'build'
}
}
}

...
...

然后,您应该继续进行剩余的项目和剩余的任务。例如, ProjB:clean应该取决于 projA:remove
project('projB') {
task clean(dependsOn: ':projA:remove') {
doLast {
println 'clean'
}
}
}

继续执行项目B和其余项目中的其他任务。

有关更多详细信息,请遵循此 link

关于gradle - 按顺序对子项目执行gradle任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48670667/

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