# How to fail/stop task immediately if some conditions are not met

**URL:** https://discuss.gradle.org/t/how-to-fail-stop-task-immediately-if-some-conditions-are-not-met/4729
**Category:** Old Forum Archive
**Created:** [June 7, 2013, 9:28pm UTC](https://discuss.gradle.org/t/how-to-fail-stop-task-immediately-if-some-conditions-are-not-met/4729 "2013-06-07T21:28:00Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)
#### Post date: [June 7, 2013, 10:16pm UTC](https://discuss.gradle.org/t/how-to-fail-stop-task-immediately-if-some-conditions-are-not-met/4729/2 "2013-06-07T22:16:00Z")

</div>

To validate a task before any task has been executed, you can use the ‘taskGraph.whenReady’ callback:

```gradle
gradle.taskGraph.whenReady { graph ->
    if (graph.hasTask(makerpm) && !hasRpmbuild()) {
        throw new GradleException("rpmbuild does not exist")
    }
}

```

---

_[View the full topic](https://discuss.gradle.org/t/how-to-fail-stop-task-immediately-if-some-conditions-are-not-met/4729)._
