Can you create gradle task that depends on gradle internal tasks?

Viewed 441

I am specifically looking to see if you can create a task that depends on the internal "assembleRelease" gradle task in a multi-project environment. There are many, many independent pieces that need building here, so changing in all of the build files is not optimal.

My basic situation is looking for a task, for example "release" that can call :a:assembleRelease, :b:assembleRelease and :c:assembleRelease without having to type in the names of all of the projects to begin with.

I have attempted the following task definition in the root project build.gradle.kts:

tasks.register("release") {
    finalizedBy(tasks.getByPath("assembleRelease"))
}

as well as tasks.getByName, and trying to go through the gradle taskGraph. The task graph doesn't appear to be the right path at all, but I'm not sure if this is a possible task or is against the conventions of gradle to do things this way.

1 Answers

You would just define a task that depends on multiple other tasks.

Assuming the root project:

tasks {
    register("release") {
        dependsOn(
            named(":a:assembleRelease"),
            named(":b:assembleRelease:),
            named(":c:assembleRelease")
        )
    }
}

You can add essentially an infinite amount of task dependencies. See Authoring Tasks for more details, specifically Adding dependencies to a task.

Related