Gradle 使用笔记

操作环境:macOS Big Sur

安装

最方便的还是使用 brew 来安装:brew install gradle,如果不太方便使用(因为会安装所依赖的 openjdk),可以采用下面的手动安装方式:

1
2
3
4
curl -LO https://services.gradle.org/distributions/gradle-7.1-bin.zip
unzip gradle-7.1-bin.zip
mv gradle-7.1/ /usr/local/Cellar/gradle
ln -s /usr/local/Cellar/gradle/bin/gradle /usr/local/bin/gradle

测试输出如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
$ gradle -v

------------------------------------------------------------
Gradle 7.1
------------------------------------------------------------

Build time: 2021-06-14 14:47:26 UTC
Revision: 989ccc9952b140ee6ab88870e8a12f1b2998369e

Kotlin: 1.4.31
Groovy: 3.0.7
Ant: Apache Ant(TM) version 1.10.9 compiled on September 27 2020
JVM: 11.0.10 (Oracle Corporation 11.0.10+8-LTS-162)
OS: Mac OS X 10.16 x86_64

Hello World

新建一个目录叫做 gradle-test,并在改目录下创建一个 build.gradle

1
2
3
mkdir gradle-test
cd gradle-test
vim build.gradle

gradle 内容如下:

1
2
3
4
5
task hello {
doLast {
println 'Hello world!'
}
}

Reference