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

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

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