gradle学习笔记(一)下载安装

        一直以来,都以为使用第三方工具或者框架有一定的弊端,但是随着项目的发展,出现了很多不可预料的问题,比如android项目的构建以及打包等,很多时候用常规的方法已经难以满足项目需求了,这个时候才知道,软件这个行业,个人的力量是有限的,适当的借助第三方工具或者框架还是有必要的,所以这里开博客记载一下关于gradle的学习印    记。

        Gradle 是以 Groovy 语言为基础,面向Java应用为主。基于DSL(领域特定语言)语法的自动化构建工具。

        为什么要学习gradle呢,其他的不说,就说android吧,在大型的android项目中,往往不是一个独立的工程所能完成的,它往往需要依赖很多的项目或者第三方库,那么这个时候去做打包时,会出现比较蛋疼的问题,编译、整合什么的,都是让人烦不胜烦的事情,废话不多说,开始吧!

       gradle下载地址:http://gradle.org/

       我这里也是第一次学习gradle,先看一下gradle的官网

    


        why gradle?这里介绍了为什么我们要使用gradle,很显然,这里说的是统一跨平台、可以集成任何东西、强大的依赖管理等等之类的。现在这些不是我所关心的,我所关心的是怎么开始和使用,学完了之后才能去了解它的好处以及优点。

      

        直接点击download转到下载页面,

       我们可以看到目前最新版本是2.10,


直接点击complete distribution下载,这里面有二进制文件以及源代码,还有帮助文档,是一个非常全的压缩包,剩下两个一个是二进制包一个是源代码。


        下载完了之后,直接点开docs,也就是文档界面,进去之后是对gradle的一些说明,我们找到,点击它,这里就是用户使用引导了,下面会列举出一系列的关于gradle的使用相关的东西。

        Copies of this document may be made for your own use and for distribution to others, provided that youdo not charge any fee for such copies and further provided that each copy contains this CopyrightNotice, whether distributed in print or electronically.这里是一些关于gradle的开源声明,资料内容不可商用!

      

        在tables content中我们找到第三个installing gradle,这个应该就是安装说明了。


3.1. Prerequisites

Gradle requires a Java JDK or JRE to be installed, version 6 or higher (to check, usejava -version).Gradle ships with its own Groovy library, therefore Groovy does not need to be installed. Any existing Groovy installation is ignored by Gradle.

Gradle uses whatever JDK it finds in your path.Alternatively, you can set the JAVA_HOME environment variable to point to the installation directoryof the desired JDK.

3.1.安装前准备

gradle需要安装jdk或者jre(6.0或者以上版本)的java环境(打开命令行输入java -version便可以查看是否安装了该环境),gradle中已经包含了groovy库,因此groovy可以不安装,


3.2. Download

You can download one of the Gradle distributions from the Gradle web site.

3.2.下载

你可以从Gradle web site上面下载gradle发布中的一个(这个之前已经下载了)


3.3. Unpacking

The Gradle distribution comes packaged as a ZIP. The full distribution contains:

  • The Gradle binaries.

  • The user guide (HTML and PDF).

  • The DSL reference guide.

  • The API documentation (Javadoc and Groovydoc).

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

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

3.3.解压缩包里面的文档结构如下


  • Gradle安装文件(\bin)

  • 帮助文档(\docs\userguide)

  • DSL参考指南(\docs\dsl)

  • api文档 (Javadoc and Groovydoc).(\docs\javadoc 和 \docs\groovydoc)

  • 提供的样本中,包括了用户指南中的例子,其中一些完善的和复杂的构建示例,可以用作你自己的构建起点(说白了就是这些例子足以让我们学会使用gradle构建自己的项目)(\samples)

  • 二进制文件仅仅是用来引用的。如果你想编译Gradle需要去下载源码,具体详情Gradle web site

3.4. Environment variables

For running Gradle, add GRADLE_HOME/bin to yourPATHenvironment variable. Usually, this is sufficient to run Gradle

运行gradle需要配置GRADLE_HOME环境变量,(就是将bin目录设置到path中,key值为GRADLE_HOME),一般来说,配置了这个东西之后就足以运行gradle了。





       

        最后别忘记将GRADLE_HOME配置到path中去。

        ok,至此,gradle的安装算是完成了,看起来还蛮简单的,嘿嘿嘿,下面就是测试一下是否安装成功了。

3.5. Running and testing your installation

You run Gradle via the gradle command. To check if Gradle is properly installed just typegradle -v. The output shows the Gradle version and also the local environment configuration (Groovy, JVM version, OS, etc.).The displayed Gradle version should match the distribution you have downloaded.

3.5.运行gradle命令gradle -v,去检查gradle是否安装成功(打开cmd命令提示符,然后直接输入gradle -v命令打回车),这会输出gradle的版本信息以及本地的环境配置(比如groovy,jvm的版本,操作系统等等)。展示出来的gradle版本信息需要跟你下载的发布版本向疲惫才行。



这里是我的安装信息,竟然把我的ant都列出来了,不简单啊!ok,到这里本章内容结束了,我很期待,下面的学习是否还是这么的轻松自如,万恶的英文字母,真的是让人感到郁闷!


3.6. JVM options

JVM options for running Gradle can be set via environment variables. You can use either GRADLE_OPTSor JAVA_OPTS, or both. JAVA_OPTS is by convention an environmentvariable shared by many Java applications. A typical use case would be to set the HTTP proxy in JAVA_OPTSand the memory options in GRADLE_OPTS. Those variables can also be set at the beginningof the gradle or gradlew script.

Note that it's not currently possible to set JVM options for Gradle on the command line.

这里说的是JVM以及jdk的参数设置,由于gradle了解的不多,具体不知道在说些什么,等学会了gradle估计就知道了吧,先不管它


猜你喜欢

转载自blog.csdn.net/q979076061/article/details/50467508