『阿男的Gradle学习笔记』*01*Gradle的安装与使用

2017-01-12 09:53:32来源:oschina作者:阿男weli人点击



『阿男的Gradle学习笔记』*01*Gradle的安装与使用
Gradle的下载地址在这里[^1]。
[^1]:http://gradle.org/gradle-download/
下载解压后,在`.bash_profile`中配置相关路径:
```bash
# Gradle
export GRADLE_HOME=/Users/weli/projs/gradle-2.14
export PATH=$PATH:$GRADLE_HOME/bin
```
测试Gradle可以使用:
```bash
$ gradle -version
------------------------------------------------------------
Gradle 2.14
------------------------------------------------------------
Build time: 2016-06-14 07:16:37 UTC
Revision: cba5fea19f1e0c6a00cc904828a6ec4e11739abc
Groovy:2.4.4
Ant: Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM: 1.8.0_40 (Oracle Corporation 25.40-b25)
OS:Mac OS X 10.11.5 x86_64
```
写一个build脚本:
```groovy
task helloWorld << {
println 'Hello, world!'
}
```
执行脚本:
```bash
$ gradle helloWorld
:helloWorld
Hello, world!
BUILD SUCCESSFUL
Total time: 3.921 secs
```
写一个依赖关系,文件命名为`build.gradle`:
```groovy
task hello << {
println 'Hello, '
}
task helloWorld(dependsOn: hello) << {
println 'world!'
}
```
执行任务:
```bash
$ gradle helloWorld
:hello
Hello,
:helloWorld
world!
BUILD SUCCESSFUL
Total time: 3.183 secs
cute:learn-gradle weli$ gradle -q helloWorld
Hello,
world!
```

最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台