Task execution order across subprojects


(Gintautas Sulskus) #1

How do I enforce a specific task execution order across subprojects?
Take for example a task build and two projects project1 and project2. How do I make sure that project2 is built before porject1?


(Chris Doré) #2

Gradle does not “build projects”, so there isn’t a concept of project execution order.
Gradle is essentially a task execution engine, and ordering is based on task dependencies. Task dependencies can be between tasks of the same project or tasks in another project.
Can you describe a bit more about what you’re dealing with?


(Gintautas Sulskus) #3

I have a multi-project build where the order of project deployments to a cloud cluster matters.
In this particular example, project2 contains resources without which project1 would fail to deploy, therefore project2 must be deployed first.

The use case here pertains kubernetes custom resource definitions (defined in project2) and resources that rely on those resource definitions (project1).


(Bob Bell) #4

So you could create file-like objects that are produced by tasks in project1, and then have those be inputs to tasks in project2, or you could simply have tasks in project1 as dependsOn prerequisites for tasks in project2. You cannot, however, automatically make all of project2 dependent upon all of project1.


(Gintautas Sulskus) #5

What I would need ideally, a mechanism to trigger :project2.task1 before :project1:task1. So the same task definition, but task1 in project2 must execute first.

Probably I will have to add either a task0 where task1.dependsOn(task1) - but that’s a bit hackish.
I believe this would be something that you suggest, @rjbell4.


(Bob Bell) #6

OK, so first the disclaimer: I’m not the expert here, so if someone contradicts me, go with them…

But why do you invent another task0? Why can you not just say dependsOn ':project2:task1' for project1's task1 task?