使用Gradle 快速构建项目
2016-01-21 09:43
344 查看
Gradle 是一款基于 Groovy 语言、免费开源的构建工具,它既保持了 Maven 的优点,又通过使用 Groovy 定义的 DSL 克服了 Maven 中使用 XML 繁冗以及不灵活的缺点。
Gradle 官方网站:http://www.gradle.org/downloads
功能
Ø gradle对多工程的构建支持很出色,工程依赖是gradle的第一公民。
Ø gradle支持局部构建。
Ø 支持多方式依赖管理:包括从maven远程仓库、nexus私服、ivy仓库以及本地文件系统的jars或者dirs
Ø gradle是第一个构建集成工具(the first build integration tool),与ant、maven、ivy有良好的相容相关性。
Ø 轻松迁移:gradle适用于任何结构的工程(Gradle can adapt to any structure you have.)。你可以在同一个开发平台平行构建原工程和gradle工程。通常要求写相关测试,以保证开发的插件的相似性,这种迁移可以减少破坏性,尽可能的可靠。这也是重构的最佳实践。
Ø gradle的整体设计是以作为一种语言为导向的,而非成为一个严格死板的框架。
Ø 免费开源
gradle提供了什么
1.一种可切换的,像maven一样的基于约定的构建框架,却又从不锁住你(约定优于配置)
Switchable, build-by-convention frameworks a la Maven. But we never lock you in!
2. 强大的支持多工程的构建
3. 强大的依赖管理(基于Apache Ivy),提供最大的便利去构建你的工程
Language for dependency based programming
4. 全力支持已有的Maven或者Ivy仓库基础建设
5. 支持传递性依赖管理,在不需要远程仓库和pom.xml和ivy配置文件的前提下
6 基于groovy脚本构建,其build脚本使用groovy语言编写
7 具有广泛的领域模型支持你的构建A rich domain model for describing your build.
Installing Gradle
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_HOMEenvironment variable to point to the installation directory of the desired JDK.
Download
You can download one of the Gradle distributions from theGradle web site.
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 more complex 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 distribution or checkout the sources from the source repository. See theGradle
web site for details.
Environment variables
For running Gradle, addGRADLE_HOME/bin[/code] to your
PATHenvironment variable. Usually, this is sufficient to run Gradle.
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 environmentconfiguration (Groovy, JVM version, OS, etc.). The displayed Gradle version should match the distribution you have downloaded.
JVM options
JVM options for running Gradle can be set via environment variables. You can use eitherGRADLE_OPTSor
JAVA_OPTS, or both.
JAVA_OPTSis 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 thegradle
orgradlew script.
Note that it's not currently possible to set JVM options for Gradle on the command line.
Getting help
You might check the user guide atGRADLE_HOME/docs/userguide/userguide.html[/code].It is also available on theGradle
web site.Typing gradle help prints the command line help. Typinggradle tasks shows all thetasks of a Gradle build.
实践操作
设置环境变量
第一步:第二步:
测试环境安装
编译构建项目
在test项目下添加build.gradle文件,并添加如下内容:apply plugin:'java'
在项目路径下,输入gradle build进行项目构建
构建完成后可以看到如下目录:
想了解更多知识参考:
Gradle User Guide
Groovy入门教程
Gradle替代maven
Groovy 闭包深入浅出
相关文章推荐
- 2016太原网络营销师郭文军分享网站图片代码优化
- Android Volley框架的使用(四)图片的三级缓存策略(内存LruCache+磁盘DiskLruCache+网络Volley)
- sregetnIowTediviD.29
- Android UI系列-----Dialog对话框
- html5-canvas标签用法
- Image Request
- 使用Pyspark编写wordcount程序
- 文字内容展开与折叠jquery代码
- C++之路进阶——树套树(陌上花开)
- Infopath表单&Reproting Service在IE11下问题解决
- "无法找到“XXX.exe”的调试信息,或者调试信息不匹配。未使用调试信息生成二进制文件"的解决方法
- 淘宝UWP--自定义图片缓存
- MKMapView简单的路线绘画
- 《iOS Human Interface Guidelines》——iAd Rich Media Ads
- 【转】Hadoop和大数据:60款顶级大数据开源工具(2015-10-27)
- TFS 强制删除工作区
- Android内嵌H5页面调用手机图片操作
- 设计模式一之策略模式
- Java EE标准体系概述
- 分页求总页数