Gradle home cannot be found on Mac

Viewed 102021

I've installed gradle on MAC using terminal.

brew install gradle

Gradle has been installed successfully.

gradle -v

------------------------------------------------------------
Gradle 3.3
------------------------------------------------------------

Build time:   2017-01-03 15:31:04 UTC
Revision:     075893a3d0798c0c1f322899b41ceca82e4e134b

Groovy:       2.4.7
Ant:          Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM:          1.8.0_112 (Oracle Corporation 25.112-b16)
OS:           Mac OS X 10.12.3 x86_64

but I can not find gradle home.

echo $GRADLE_HOME
[empty result]

the first step to determine home directory is detect location of gradle instruction:

which gradle
/usr/local/bin/gradle

there is incomprehensible bash file.


Any ideas how to detect gradle home directory via terminal?

7 Answers

You can retrieve the path for GRADLE_HOME automatically using the following snippet in your .bashrc or .zshrc:

export GRADLE_HOME=$(brew info gradle | grep /usr/local/Cellar/gradle | awk '{print $1}')

This is handy when the path to Gradle's home changes, when Gradle is updated.

On Mojave (v10.14), Gradle v5.4, I had to append libexec after Gradle version for IntelliJ to work.

/usr/local/Cellar/gradle/5.4/libexec

I've gradle installed When using homebrew, below one failed with me, and kept telling undefined:

/usr/local/Cellar/gradle/<version>

The below symlink worked perfectly, and solved my issue:

/usr/local/opt/gradle/libexec

"brew info gradle" command not always give the installed path

br*ew info gradle
gradle: stable 5.6.3
Open-source build automation tool based on the Groovy and Kotlin DSL
https://www.gradle.org/
Not installed
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/gradle.rb
==> Requirements
Required: java >= 1.8 ✔
==> Analytics
install: 29,106 (30 days), 144,607 (90 days), 611,211 (365 days)
install_on_request: 28,237 (30 days), 137,584 (90 days), 577,691 (365 days)
build_error: 0 (30 days)*

On Mojave, Gradle v6.6, I appended libexec after Gradle version for IntelliJ to work.

/usr/local/Cellar/gradle/5.4/libexec

My point isn't enough for commenting on flic's answer in the previous post. If it happens to be in MacOS, the asterisk should be escaped as:

brew info gradle | sed -nE 's#^(/usr/local/Cellar/gradle/[^ ]+).+\*#\1#p'

or there will be sed: 1: "s#^(/usr/local/Cellar/g ...: RE error: repetition-operator operand invalid" error reported.

Related