首先確保你java環(huán)境已經(jīng)OK, 即jdk已經(jīng)安裝,可以執(zhí)行命令檢查:
????????$ java -version
會輸出如下:
? ? ? ? ?java version "1.8.0_131"
????????Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
????????Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)
gradle的安裝方式有多種,可以自行選擇
方式一: 命令安裝 如果安裝過Homebrew,可以直接用如下,
? ??????$ brew install gradle
方式二: 手動安裝 在 Gradle 官網(wǎng)https://gradle.org/gradle-download/ 下載所需版本,解壓下,設(shè)置環(huán)境變量在.bash_profile文件中添加
????????unzip ~/Downloads/gradle-4.1-all.zip -d /usr/local/gradle/ &&\
????????echo '# Adding Gradle to system path
????????export GRADLE_HOME=/usr/local/gradle/gradle-4.1
????????PATH=$GRADLE_HOME/bin:$PATH
????????export PATH' >> ~/.bash_profile &&\
????????source ~/.bash_profile
如果上一步完成了,你可以運(yùn)行下面命令gradle --version檢驗?zāi)闶欠裨O(shè)置成功
????????$ gradle --version
輸出對應(yīng)的gradle版本:
????????------------------------------------------------------------
????????Gradle 4.1
????????------------------------------------------------------------
????????Build time:2017-08-07 14:38:48 UTC
????????Revision:941559e020f6c357ebb08d5c67acdb858a3defc2
????????Groovy:2.4.11
????????Ant:Apache Ant(TM) version 1.9.6 compiled on June 29 2015
????????JVM:1.8.0_131 (Oracle Corporation 25.131-b11)
????????OS:Mac OS X 10.13.1 x86_64
如下可以建一個build.gradle , 建立個helloWorld task運(yùn)行命令試下
$ gradle helloWorld
task helloWorld {
????????doLast{
????????????println "Hello, World!"
????????}
}