Java 在 Mac 上找不到 Gradle 主页

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/44367082/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 01:30:34  来源:igfitidea点击:

Gradle home cannot be found on Mac

javabashmacosgradle

提问by Sergii

I've installed gradleon MAC using terminal.

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

brew install gradle

brew install gradle

Gradle has been installed successfully.

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

but I can not find gradle home.

但我找不到 gradle 家。

echo $GRADLE_HOME
[empty result]

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

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

which gradle
/usr/local/bin/gradle

there is incomprehensible bash file.

有无法理解的 bash 文件。



Any ideas how to detect gradle home directory via terminal?

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

采纳答案by dvelopp

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

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

回答by jokoso

You can retrieve the path for GRADLE_HOMEautomatically using the following snippet in your .bashrcor .zshrc:

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

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

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

当 Gradle 的 home 路径改变时,当 Gradle 更新时,这很方便。

回答by Chinbat G.

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:

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

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

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

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

回答by Hasan A Yousef

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

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

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

The below symlink worked perfectly, and solved my issue:

以下符号链接完美运行,并解决了我的问题:

/usr/local/opt/gradle/libexec

回答by moazzem

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

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

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

回答by SNL

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

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

回答by Sunil

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

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

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