Conditional task dependencies

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?

This circumstance is called out in the “Ordering tasks” section of the User Guide.