Stop a Gradle Build with an Error: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 10: Line 10:


=Example=
=Example=
<syntaxhighlight lang='groovy'>
ext {
    String s = System.getenv("REQUIRED_ENVIRONMENT_VARIABLE");
    if (s == null) {
        throw new InvalidUserDataException("this Gradle build needs 'REQUIRED_ENVIRONMENT_VARIABLE' environment variable to be defined and meaningful, but the variable was not found in the environment!");
    }
}
</syntaxhighlight>


=Organizatorium=
=Organizatorium=

Revision as of 21:41, 14 March 2019

Internal

Overview

To stop Gradle in the configuration phase with an error, usually caused by user input, or missing configuration, throw the relevant exception from org.gradle.api package:

Example

ext {

    String s = System.getenv("REQUIRED_ENVIRONMENT_VARIABLE");

    if (s == null) {

        throw new InvalidUserDataException("this Gradle build needs 'REQUIRED_ENVIRONMENT_VARIABLE' environment variable to be defined and meaningful, but the variable was not found in the environment!");
    }
}

Organizatorium