Novaterata
Novaterata

Reputation: 4781

How to ignore dependsOn failure because some subprojects don't have the defined task

I have a multi-project gradle build where not all of the subprojects have the same plugin, but I would like to define tasks in the root build.gradle file like this:

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

Not all subprojects have "jacocoTestReport" or "integrationTests" defined, but this task will fail because of that fact. How do I configure this to work, and frankly, why is the default behavior so strict?

Upvotes: 0

Views: 632

Answers (1)

Novaterata
Novaterata

Reputation: 4781

This is what ended up working for me:

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

And I forgot that I actually needed to run integrationTests in a doLast, which looks like this:

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

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

Upvotes: 0

Related Questions