58

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?

Sergii
  • 7,044
  • 14
  • 58
  • 116
  • I would guess that either you don't need `$GRADLE_HOME` because gradle uses a sensible default, or `brew` has put `GRADLE_HOME` in a login script. Try logging out and back in. – slim Jun 05 '17 at 10:43
  • 5
    `brew info gradle` – Oliver Charlesworth Jun 05 '17 at 10:44
  • 3
    @slim, completely agree. I do not need to set up `$GRADLE_HOME`. But I need how to detect one because of some IDE wants me to define correspond path in configuration. – Sergii Jun 05 '17 at 10:46
  • @oliver-charlesworth, it really works for me. I've run the command and got good enough information about installed `gradle` (home directory also). – Sergii Jun 05 '17 at 10:49
  • refer https://stackoverflow.com/questions/18495474/how-to-define-gradles-home-in-idea – pungoyal Aug 13 '17 at 05:43

7 Answers7

99

You can use command:

brew info gradle

As the result you will have something like this:

gradle: stable 4.0.1
Build system based on the Groovy language
https://www.gradle.org/
/usr/local/Cellar/gradle/3.4 (181 files, 74.5MB) *
  Built from source on 2017-02-24 at 15:01:34
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/gradle.rb
==> Requirements
Required: java >= 1.7 ✔
==> Options
--with-all
    Installs Javadoc, examples, and source in addition to the binaries

Here, on the line 4 you can see the home path : /usr/local/Cellar/gradle/3.4

dvelopp
  • 4,095
  • 3
  • 31
  • 57
31

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.

jokoso
  • 431
  • 4
  • 6
  • 2
    If there are multiple versions installed, the above will grab the first version in the list. If you want the current version in use (marked with an asterisk * at the end), try this instead: brew info gradle | sed -nE 's#^(/usr/local/Cellar/gradle/[^ ]+).+\*#\1#p' – Flic Apr 26 '18 at 05:21
  • 3
    It is worth mentioning that adding this into your bash profile file will slowdown shell initialisation because `brew info gradle` actually takes some time. – eleven Jan 18 '19 at 12:11
27

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
Moazzem Hossen
  • 2,276
  • 1
  • 19
  • 30
8

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
Hasan A Yousef
  • 22,789
  • 24
  • 132
  • 203
6

"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)*
SNL
  • 79
  • 1
  • 4
3

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

/usr/local/Cellar/gradle/5.4/libexec
Sandeep Kumar
  • 2,397
  • 5
  • 30
  • 37
Sunil
  • 31
  • 1
1

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.

Jeel Vankhede
  • 11,592
  • 2
  • 28
  • 58
Chinbat G.
  • 155
  • 1
  • 8