Hi, i’m looking to have some conditional logic che...
# gradle
s
Hi, i’m looking to have some conditional logic checks in my
settings.gradle
that i’d like to use to short circuit the build during the initialization stage. Currently this is what i have
Copy code
gradle.settingsEvaluated {
    if (failConditionIsTrue) {
        throw GradleException("Helpful message explaining the cause of the error")
    }
}
Is there a better way to do this? possibly throw the exception as a first step in the initialization phase?
v
I'm not sure what you mean with the last sentence. And if you want it as first step, why do you do it as last step using
settingsEvaluated
instead of just doing the check?
s
I mean that i would like to do the check as the absolute first step, however just doing the check does not immediately stop the build and show the “helpful” error message while using
settingsEvaluated
stops build in its tracks and displays the error message in the IDE
v
Either stops the build with the meaningful exception. Not having
settingsEvaluated
immediately, with
settingsEvaluated
after the settings script was evaluated. If you execute the build you also see the exception in the IDE either way. If you just sync the Gradle project, you just get the warning that something happend with the first variante. But that's an IntelliJ specific "issue". If you want it changed, you should open an issue with JetBrains. But as far as Gradle is concerned, my answer stands. 🙂
s
makes sense, i personally prefer the variant that throws the exception on sync as well, thank you 😄
v
It does throw the exception, IJ just displays it differently. That's why I said you might open an issue with them to maybe improve.
s
yes, i will definitely open an issue 🙂