Recommended way to stop a Gradle build

Kartoch picture Kartoch · Apr 25, 2012 · Viewed 71.8k times · Source

How can I stop a Gradle build after detecting a problem? I can use an assert, throw an exception, do a System.exit (bad idea), or use a dedicated function in Gradle (but I could not find one). What is the best way for Gradle (and why?).

Answer

tim_yates picture tim_yates · Apr 25, 2012

I usually throw the relevant exception from the org.gradle.api package, for example InvalidUserDataException for when someone has entered something invalid, or GradleScriptException for more general errors.

If you want to stop the current task or action, and move on to the next, you can also throw a StopActionException