Execute tasks sequentially in some task

I have a library, which contains 3 lib modules and 1 example module. Before deploy task I want to execute some other tasks. In command line it looks like this: ./gradlew -x:example:clean -x:example:check -x:example:uploadArchives clean check :androidLib:assembleRelease uploadArchives.

I want to write gradle task to execute all tasks sequentially for all modules besides example module. That I can do: ./gradlew deployAll. How can i do it?

I try do this:

task deployAll {
doLast {
    subprojects {
         if(it.plugins.withType(com.android.build.gradle.AppPlugin)) return
         it.tasks.getByName('clean').execute()
         it.tasks.getByName('check').execute()
         ...
    }
}

}

But execute() is deprecated and it execute only first task and ignore any.

Hi Alexey,

can you use dependsOn, mustRunAfter and shouldRunAfter to model your dependencies? IIUC, you want the deployAll task to depend on clean and check, right? Is that all you need to do?

Cheers,
Stefan

Hi Stefan,

I want, that I can execute only my task deployAll and this executing all the tasks listed in it in order automatically for each subproject.

What stops you from using dependsOn and shouldRunAfter? Does using those methods have some unwanted side effects for you?

Can you help me, how correct to use these? Something like this?

task deployAll {
    doLast {
        subprojects {
             if(it.plugins.withType(com.android.build.gradle.AppPlugin)) return
             
             it.tasks.getByName('check') shouldRunAfter it.tasks.getByName('clean')
             // and then call it.tasks.getByName('clean').execute() ? or how?
             ...
        }
    }
}

I was more thinking in terms of:

task deployAll {
    dependsOn(subprojects*.tasks*.getByName('clean'))
    dependsOn(subprojects*.tasks*.getByName('check'))
}

When you now run deployAll, the clean and check tasks will be executed, too.

The if statement in you subproject block is there since you don’t want to depend on projects which have the AppPlugin applied?

1 Like

Thanks! I will try this solution.

Yes, I don’t want to execute these tasks in project, which have the AppPlugin.