我在以下目录结构中有一个gradle composite build。
.
├── component-1
├── component-2
├── component-3
└── composite-build
这里所有的组件都是multi-project builds,每个组件都实现了release plugin,可以单独发布,composite-build
有以下settings.gradle
。
rootProject.name = 'composite-build'
includeBuild '../component-1'
includeBuild '../component-2'
includeBuild '../component-3'
我想以特定的顺序执行每个组件的release
任务,但我找不到合适的方法。以下是我尝试过但失败的一些案例。在这些案例中,个别release
任务也会因为发布插件所做的git标签提交冲突而失败。
案例1:
单位:build.gradle
task releaseAll {
dependsOn gradle.includedBuild('component-1').task(':release')
dependsOn gradle.includedBuild('component-2').task(':release')
dependsOn gradle.includedBuild('component-3').task(':release')
}
案例2:
单位:build.gradle
task releaseComponent1 {
dependsOn gradle.includedBuild('component-1').task(':release')
}
task releaseComponent2 {
dependsOn gradle.includedBuild('component-2').task(':release')
}
task releaseComponent3 {
dependsOn gradle.includedBuild('component-3').task(':release')
}
releaseComponent2.configure {
mustRunAfter releaseComponent1
}
releaseComponent3.configure {
mustRunAfter releaseComponent2
}
task releaseAll {
dependsOn releaseComponent1
dependsOn releaseComponent2
dependsOn releaseComponent3
}
错误消息示例:
> Task :component-1:component-1-release:preTagCommit FAILED
Running [git, commit, -m, [Gradle Release Plugin] - pre tag commit: 'component-1-0.1.10'., -a] produced an error: []
Running [git, push, --porcelain, origin, main] produced an error: [error: failed to push some refs to 'https://github.com/<username>/<repo-name>.git']
> Task :component-1:release FAILED
Release process failed, reverting back any changes made by Release Plugin.
Running [git, checkout, gradle.properties] produced an error: [error: pathspec 'gradle.properties' did not match any file(s) known to git]
1: Task failed with an exception.
-----------
* What went wrong:
Execution failed for task ':component-1:component-1-release:preTagCommit'.
> Failed to push to remote - [To https://github.com/<username>/<repo-name>.git
! refs/heads/main:refs/heads/main [remote rejected] (cannot lock ref 'refs/heads/main': is at <xxxx> but expected <yyyy>)
Done
][error: failed to push some refs to 'https://github.com/<username>/<repo-name>.git'
]
1条答案
按热度按时间kkih6yb81#
Gradle始终提供一个选项,您可以使用
finalizedBy
自动执行并链接任务执行,您还可以测试这段简单的代码以检查其工作方式:这样,通过调用
gradle C
,它将回溯执行A
,然后执行B
,最后执行C
同样,您可以执行3个任务来获得所需的有序执行,如下所示
通过调用
gradle releaseAll
,它将首先执行c1release
,然后执行c2release
,最后执行c3release
但我还是希望我能知道你在问题中所包括的案例中有什么样的错误。