我有一个多项目gradle构建,其中并非所有子项目都具有相同的插件,但是我想在根build.gradle文件中定义任务,如下所示:

subprojects {
    task continuousBuild(dependsOn: ["clean", "check", "jacocoTestReport", "integrationTests"]
}

并非所有子项目都定义了“jacocoTestReport”或“integrationTests”,但是由于这个事实,此任务将失败。我如何配置它才能正常工作,坦率地说,为什么默认行为如此严格?

最佳答案

这就是对我有用的东西:

   task continuousBuild(dependsOn: ['clean', 'check']) {
        def uncommonTasks = ['jacocoTestReport', 'integrationTests']
        dependsOn += tasks
                .findAll { uncommonTasks.contains(name) }
   }

而且我忘记了我实际上需要在doLast中运行IntegrationTests,如下所示:
    task continuousBuild(dependsOn: ['clean', 'check']) {
        dependsOn += tasks
                .findAll { 'jacocoTestReport' == name) }

        if (tasks.findByName('integrationTests')) {
            doLast {
                integrationTests
            }
        }
    }

关于gradle - 如何忽略dependsOn失败,因为某些子项目没有定义的任务,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48991375/

10-12 02:41