# Conditional task dependencies

**URL:** <https://discuss.gradle.org/t/conditional-task-dependencies/41768>\
**Category:** Help/Discuss\
**Created:** [December 23, 2021, 7:38pm UTC](https://discuss.gradle.org/t/conditional-task-dependencies/41768 "2021-12-23T19:38:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bgeradz](https://avatars.discourse-cdn.com/v4/letter/b/ed655f/32.png) [@bgeradz](https://discuss.gradle.org/u/bgeradz)\
**Post date:** [December 23, 2021, 7:38pm UTC](https://discuss.gradle.org/t/conditional-task-dependencies/41768/1 "2021-12-23T19:38:59Z")

</div>

Let’s say I have 3 tasks, `clean`, `build` and `deploy`  
In order to deploy I need to first `clean` and then `build`

Using dependsOn, I would need to make `deploy` depend on `clean ` and `build`  
and also `build` depend on `clean` to force the correct order.  
But making `build` _always_ depend on `clean` is something one would naturally wish to avoid.

Is there a way to make the latter dependency conditional that is only in context of `deploy` task?

---

<div class="post-metadata">

**Author:** ![jjustinic](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/jjustinic/32/9005_2.png) [@jjustinic](https://discuss.gradle.org/u/jjustinic)\
**Post date:** [December 23, 2021, 7:55pm UTC](https://discuss.gradle.org/t/conditional-task-dependencies/41768/2 "2021-12-23T19:55:40Z")

</div>

This circumstance is called out in the [“Ordering tasks” section of the User Guide](https://docs.gradle.org/current/userguide/more_about_tasks.html#sec:ordering_tasks).
