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?).
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