others - Java - 在Mac上,无法找到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



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

时间:

你可以使用命令:

 
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

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


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



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


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



下面的符号链接工作正常,并解决了我的问题:


/usr/local/opt/gradle/libexec



如果恰好在macOS中,则应转义为:


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



否则会有 sed: 1:"s#^(/usr/local/Cellar/g ... : re error : repetition-operator operand invalid "error reported .

...