这里以mac为例安装gradle,其实windows同理。
安装
使用Homebrew
- 在线安装homebrew:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
- 安装gradle
brew install gradle
手动安装
- 先下载gradle,官网地址:https://gradle.org/releases/ 选择你需要安装的版本,然后解压到你的选择的目录下(这里以/usr/local/gradle为例)
- 配置gradle环境变量
编辑 .bash_profile:
export GRADLE_HOME=/usr/local/gradle/gradle-6.0.1
更新 PATH环境变量(这里不要照抄):
export PATH=$GRADLE_HOME/bin:$PATH
应用配置:
source ~/.bash_profile
验证
> gradle -v
Welcome to Gradle 5.4.1!
Here are the highlights of this release:
- Run builds with JDK12
- New API for Incremental Tasks
- Updates to native projects, including Swift 5 support
For more details see https://docs.gradle.org/5.4.1/release-notes.html
------------------------------------------------------------
Gradle 5.4.1
------------------------------------------------------------
Build time: 2019-04-26 08:14:42 UTC
Revision: 261d171646b36a6a28d5a19a69676cd098a4c19d
Kotlin: 1.3.21
Groovy: 2.5.4
Ant: Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM: 1.8.0_91 (Oracle Corporation 25.91-b14)
OS: Mac OS X 10.14.6 x86_64
配置本地repository目录
- 添加GRADLE_USER_HOME环境变量,这里我们以复用maven仓库为例:
vi ~/.bash_profile
GRADLE_USER_HOME=/Users/caowg/.m2/repository
export GRADLE_USER_HOME
- 使配置生效
source ~/.bash_profile
- 注意,如果安装了zsh
先vi ~/.zshrc
添加:source ~/.bash_profile
然后 source ~/.zshrc
如对您有帮助欢迎点赞,留言讨论,谢谢。
网友评论