# Task execution order across subprojects

**URL:** <https://discuss.gradle.org/t/task-execution-order-across-subprojects/27599>\
**Category:** Help/Discuss\
**Created:** [July 3, 2018, 11:58am UTC](https://discuss.gradle.org/t/task-execution-order-across-subprojects/27599 "2018-07-03T11:58:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![gintautassulskus](https://avatars.discourse-cdn.com/v4/letter/g/c77e96/32.png) [@gintautassulskus](https://discuss.gradle.org/u/gintautassulskus)\
**Post date:** [July 3, 2018, 11:58am UTC](https://discuss.gradle.org/t/task-execution-order-across-subprojects/27599/1 "2018-07-03T11:58:30Z")

</div>

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`?

---

<div class="post-metadata">

**Author:** ![Chris\_Dore](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/chris_dore/32/7592_2.png) [@Chris\_Dore](https://discuss.gradle.org/u/Chris_Dore)\
**Post date:** [July 8, 2018, 11:03pm UTC](https://discuss.gradle.org/t/task-execution-order-across-subprojects/27599/2 "2018-07-08T23:03:52Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![gintautassulskus](https://avatars.discourse-cdn.com/v4/letter/g/c77e96/32.png) [@gintautassulskus](https://discuss.gradle.org/u/gintautassulskus)\
**Post date:** [July 12, 2018, 2:37pm UTC](https://discuss.gradle.org/t/task-execution-order-across-subprojects/27599/3 "2018-07-12T14:37:55Z")

</div>

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`).

---

<div class="post-metadata">

**Author:** ![rjbell4](https://avatars.discourse-cdn.com/v4/letter/r/8c91f0/32.png) [@rjbell4](https://discuss.gradle.org/u/rjbell4)\
**Post date:** [July 14, 2018, 5:10am UTC](https://discuss.gradle.org/t/task-execution-order-across-subprojects/27599/4 "2018-07-14T05:10:14Z")

</div>

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`.

---

<div class="post-metadata">

**Author:** ![gintautassulskus](https://avatars.discourse-cdn.com/v4/letter/g/c77e96/32.png) [@gintautassulskus](https://discuss.gradle.org/u/gintautassulskus)\
**Post date:** [July 14, 2018, 7:40pm UTC](https://discuss.gradle.org/t/task-execution-order-across-subprojects/27599/5 "2018-07-14T19:40:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rjbell4](https://avatars.discourse-cdn.com/v4/letter/r/8c91f0/32.png) [@rjbell4](https://discuss.gradle.org/u/rjbell4)\
**Post date:** [July 14, 2018, 7:59pm UTC](https://discuss.gradle.org/t/task-execution-order-across-subprojects/27599/6 "2018-07-14T19:59:56Z")

</div>

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?
