在Mac上找不到Gradle home

时间:2017-06-05 10:37:23

标签: java bash macos gradle

我已经使用终端在MAC上安装了gradle

brew install gradle

Gradle已成功安装。

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

但我找不到gradle home。

echo $GRADLE_HOME
[empty result]

确定主目录的第一步是检测gradle指令的位置:

which gradle
/usr/local/bin/gradle

有难以理解的bash文件。

如何通过终端检测gradle主目录?

7 个答案:

答案 0 :(得分:47)

您可以使用命令:

brew info gradle

结果你会得到这样的东西:

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

此处,在第4行,您可以看到主路径:/usr/local/Cellar/gradle/3.4

答案 1 :(得分:14)

您可以使用GRADLE_HOME.bashrc中的以下代码段自动检索.zshrc的路径:

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

当Gradle更新时,当Gradle主页的路径发生变化时,这很方便。

答案 2 :(得分:3)

“ brew info gradle”命令并不总是给出安装路径

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)*

答案 3 :(得分:2)

在Mojave的Gradle v6.6上,我在Gradle版本之后附加了libexec,以使IntelliJ正常工作。

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

答案 4 :(得分:0)

我已经安装了gradle在使用自制软件时,下面的一个失败了,并一直告诉未定义:

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

下面的符号链接运行良好,并解决了我的问题:

/usr/local/opt/gradle/libexec

答案 5 :(得分:0)

在Mojave(v10.14),Gradle v5.4上,我必须在Gradle版本之后附加libexec才能使IntelliJ正常工作。

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

答案 6 :(得分:-1)

我的观点还不足以评论上一篇文章中flic的答案。 如果恰好在MacOS中,则应将星号转义为:

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

否则将出现sed: 1: "s#^(/usr/local/Cellar/g ...:RE错误:报告了重复运算符操作数无效”错误。