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

『阿男的Gradle学习笔记』 *01*Gradle的安装与使用
本节课视频:

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

Gradle的下载地址: http://gradle.org/gradle-download/

下载解压后,在.bash_profile中配置相关路径:

# Gradle
export GRADLE_HOME=/Users/weli/projs/gradle-2.14
export PATH=$PATH:$GRADLE_HOME/bin


测试Gradle可以使用:

cute:dev-diary weli$ 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脚本:

task helloWorld << {
	println 'Hello, world!'
}


执行脚本:

cute:learn-gradle weli$ gradle helloWorld
:helloWorld
Hello, world!

BUILD SUCCESSFUL

Total time: 3.921 secs


写一个依赖关系:

task hello << {
	println 'Hello, '
}

task helloWorld(dependsOn: hello) << {
	println 'world!'
}


执行任务:

cute:learn-gradle weli$ gradle helloWorld
:hello
Hello,
:helloWorld
world!

BUILD SUCCESSFUL

Total time: 3.183 secs
cute:learn-gradle weli$ gradle -q helloWorld
Hello,
world!