Build Failed with an Exception

Background: I am trying to set up Gradle for use on my Mac.
Initial Steps: I installed Gradle using homebrew. I then tried verifying the installation with “$ gradle -v” and got the following message:

FAILURE: Build failed with an exception.

* What went wrong:
ch.qos.logback.classic.LoggerContext cannot be cast to org.gradle.internal.logging.slf4j.OutputEventListenerBackedLoggerContext

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

* Get more help at

When I run the same command with the --stacktrace, --info, or --debug tag I get the exact same output. I also tried exporting the PATH of the gradle bin directory by putting the following in my ~/.bash_profile:

export PATH="$PATH:/usr/local/Cellar/gradle/4.2.1/bin/"

Unfortunately this did not help in any way. Please let me know if you know how to fix this or have any ideas.
Thanks in advance.

That is strange - it should not happen. I cannot directly tell you what is wrong.

I am though, going to suggest that you uninstall the Homebew version and rather use SDKMan to manage your Gradle installations. It should save you a lot of hassle in future, not only for Gradle, but also for a number of other SDKs and applications.

Hey so using SDKMan did not help, but updating my JDK did help. I was running 1.8.0_20, but after updating to 9 I was able to get the gradle -v to output the following:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.reflection.CachedClass (file:/Users/alexjohnson/.sdkman/candidates/gradle/4.2.1/lib/groovy-all-2.4.12.jar) to method java.lang.Object.finalize()
WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.reflection.CachedClass
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

Gradle 4.2.1

Build time:   2017-10-02 15:36:21 UTC
Revision:     a88ebd6be7840c2e59ae4782eb0f27fbe3405ddf

Groovy:       2.4.12
Ant:          Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM:          9 (Oracle Corporation 9+181)
OS:           Mac OS X 10.12.6 x86_64

Which is not perfect, but still much better than the exception I was getting earlier.

This is just a warning. Please for more information.