如何忽略dependsOn失败,因为某些子项目没有定义的任务

时间:2018-02-26 15:00:51

标签: gradle build.gradle multi-project

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

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

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

1 个答案:

答案 0 :(得分:0)

最终为我工作的是:

   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
            }
        }
    }