第四章. 安装Gradle

Chapter 4. Installing Gradle

4.1. 环境要求

4.1. Prerequisites

Gradle需要安装Java6或更高以上版本的JDK或JRE。Gradle自带了Groovy库,因此不需要安装Groovy。已经安装的Groovy会被Gradle所忽略。
Gradle requires a Java JDK or JRE to be installed. Gradle requires a Java version 6 or higher. Gradle ships with its own Groovy library, therefore no Groovy needs to be installed. Any existing Groovy installation is ignored by Gradle.

Gradle会使用在您的path环境变量中找到的JDK(可以使用java -version命令来检查自己的JDK版本)。 另外,您也可以设置 JAVA_HOME 环境变量来指向你想要的JDK的安装目录。
Gradle uses whichever JDK it finds in your path (to check, use java -version). Alternatively, you can set the JAVA_HOME environment variable to point to the install directory of the desired JDK.

4.2. 下载

4.2. Download

您可以从Gradle 官方网站上下载Gradle的发行包。
You can download one of the Gradle distributions from the Gradle web site.

4.3. 解压

4.3. Unpacking

Gradle的发行包是一个ZIP文件。完整的发行包包含以下内容:
The Gradle distribution comes packaged as a ZIP. The full distribution contains:

  • Gradle可执行文件。

    The Gradle binaries.

  • 用户指南(HTML和PDF两种版本)。

    The user guide (HTML and PDF).

  • DSL参考指南。

    The DSL reference guide.

  • API文档(包括Javadoc和Groovydoc)。

    The API documentation (Javadoc and Groovydoc).

  • 大量的样例,包括用户指南里的例子,以及一些完整的和更加复杂的构建。您可以把它们作为您自己的构建的基础。

    Extensive samples, including the examples referenced in the user guide, along with some complete and more complex builds you can use the starting point for your own build.

  • 源代码。这些源代码仅供参考。如果您想要自己来编译Gradle,您需要去下载源码发行包,或者是从源码仓库里检出代码。具体请参阅Gradle官方网站

    The binary sources. This is for reference only. If you want to build Gradle you need to download the source distribution or checkout the sources from the source repository. See the Gradle web site for details.

4.4. 环境变量

4.4. Environment variables

要运行Gradle,您需要将 GRADLE_HOME/bin 添加到您的 PATH环境变量中。通常添加了之后就可以运行Gradle了。
For running Gradle, add GRADLE_HOME/bin to your PATH environment variable. Usually, this is sufficient to run Gradle.

4.5. 运行和测试您的安装

4.5. Running and testing your installation

您可以通过gradle命令来运行Gradle。输入gradle -v就可以检查Gradle是否被正确安装。该命令会输出Gradle的版本,以及本地环境的配置(groovy和JVM版本等等)。所显示的Gradle版本应该与您已经安装的发行包相匹配。
You run Gradle via the gradle command. To check if Gradle is properly installed just type gradle -v. The output shows Gradle version and also local environment configuration (groovy and JVM version, etc.). The displayed Gradle version should match the distribution you have downloaded.

4.6. JVM 选项

4.6. JVM options

Gradle运行时的JVM参数可以通过GRADLE_OPTS 或是 JAVA_OPTS的环境变量来设置,这些环境变量也可以一起使用。习惯上, JAVA_OPTS 是一个与其他Java应用程序共享的环境变量,一个典型的场景是在 JAVA_OPTS 中设置HTTP代理,而在GRADLE_OPTS中设置内存选项。这些环境变量也可以在 gradlegradlew 脚本文件的开头设置。
JVM options for running Gradle can be set via environment variables. You can use GRADLE_OPTS or JAVA_OPTS. Those variables can be used together. JAVA_OPTS is by convention an environment variable shared by many Java applications. A typical use case would be to set the HTTP proxy in JAVA_OPTS and the memory options in GRADLE_OPTS. Those variables can also be set at the beginning of the gradle or gradlew script.