【Gradle Build Tool 4.1用户指南】Chapter 2.Overview 第二章、概述
来源:互联网 发布:淘宝上奇怪的东西 编辑:程序博客网 时间:2024/05/22 14:34
Table of Contents 内容目录
2.1. Features 特点
2.2. Why Groovy? 为什么是Groovy?
2.1. Features
特点
Here is a list of some of Gradle's features.
下面列举出Gradle的特点。
Declarative builds and build-by-convention.
构建声明和基于惯例构建。
At the heart of Gradle lies a rich extensible Domain Specific Language (DSL) based on Groovy. Gradle pushes declarative builds to the next level by providing declarative language elements that you can assemble as you like. Those elements also provide build-by-convention support for Java, Groovy, OSGi, Web and Scala projects. Even more, this declarative language is extensible.Add your own new language elements or enhance the existing ones, thus providing concise, maintainable and comprehensible builds.
Gradle的核心存在大量可扩展的基于Groovy语言的DSL。Gradle通过提供可以组装的说明性语言元素将说明性构建推到下一层。这些元素还支持Java、Groovy、OSGi、Web和Scala项目的按惯例构建。甚至,这些说明性语言是可扩展的。添加你自己新的语言元素或者提高现有的语言元素,可以提供简洁、易于维护和理解的构建。
Language for dependency based programming
基于依赖的编程语言
The declarative language lies on top of a general purpose task graph, which you can fully leverage in your builds. It provides utmost flexibility to adapt Gradle to your unique needs.
说明性语言位于通用任务列表之上,可以在工程里充分利用这一点。它提供了最大的灵活性,以适应你对Gradle的独特需求。
Structure your build
构建你的工程
The suppleness and richness of Gradle finally allows you to apply common design principles to your build. For example, it is very easy to compose your build from reusable pieces of build logic. Inline stuff where unnecessary indirections would be inappropriate. Don't be forced to tear apart what belongs together (e.g. in your project hierarchy). Avoid smells like shotgun changes or divergent change that turn your build into a maintenance nightmare. At last you can create a well structured, easily maintained, comprehensible build.
由于gradle的灵活性和丰富性,可以将最常用的设计原则应用到工程里面。比如,将可重用的构建逻辑块组装在一起是非常容易的。把不必要又没有直接联系的内容内联在一起是不合适的。而应该在一起的模块不能被强制分开(例如,项目的层次结构)。避免“霰弹式变化”或“发散式变化”的代码坏味道使你的构建变成一场维护噩梦。至少,你可以创建一个结构良好、易于维护、易于理解的构建。
Deep API
深层API
From being a pleasure to be used embedded to its many hooks over the whole lifecycle of build execution, Gradle allows you to monitor and customize its configuration and execution behavior to its very core.
在构建执行的整个生命周期中,由于习惯于嵌入很多钩子,Gradle允许你监视以及定制它的配置和核心的执行行为。
Gradle scales
Gradle的使用范围
Gradle scales very well. It significantly increases your productivity, from simple single project builds up to huge enterprise multi-project builds. This is true for structuring the build. With the state-of-art incremental build function, this is also true for tackling the performance pain many large enterprise builds suffer from.
Gradle的使用范围广泛。从简单的单项目构建,到大型的企业多项目构建,它都可以有效地提高效率。这不仅对结构化构建是真实的,而且,随着构建技术水平日益增加,对解决许多大型企业构建所遭遇的性能难题也是如此。
Multi-project builds
多项目构建
Gradle's support for multi-project build is outstanding. Project dependencies are first class citizens. We allow you to model the project relationships in a multi-project build as they really are for your problem domain. Gradle follows your layout not vice versa.
Gradle对多项目构建的支持非常出色。优先解决项目依赖。我们允许您在一个多项目构建中为项目关系进行建模,因为它们真的适用于您的问题域。Gradle遵循您的布局,而非相反。
Gradle provides partial builds. If you build a single subproject Gradle takes care of building all the subprojects that subproject depends on. You can also choose to rebuild the subprojects that depend on a particular subproject. Together with incremental builds this is a big time saver for larger builds.
Gradle提供了部分构建。如果你是在构建一个子项目,Gradle将负责构建这个子项目所依赖的所有子项目。你也可以选择重新构建依赖于特定子项目的所有子项目。对大型构建和增量构建来说,这是一个大的节省时间的方法。
Many ways to manage your dependencies
管理依赖关系的多种方法
Different teams prefer different ways to manage their external dependencies. Gradle provides convenient support for any strategy. From transitive dependency management with remote Maven and Ivy repositories to jars or directories on the local file system.
不同的团队倾向于不同的方法来管理它们的外部依赖关系。Gradle为任何策略都提供方便的支持。从远程Maven和Ivy库的传递依赖管理,到本地文件系统中的jar或目录。
Gradle is the first build integration tool
Gradle是第一个集成的构建工具
Ant tasks are first class citizens. Even more interesting, Ant projects are first class citizens as well. Gradle provides a deep import for any Ant project, turning Ant targets into native Gradle tasks at runtime. You can depend on them from Gradle, you can enhance them from Gradle, you can even declare dependencies on Gradle tasks in your build.xml. The same integration is provided for properties, paths, etc ...
Ant任务是最优先的,更有趣的是,Ant项目也是最优先的。Gradle为任何的Ant项目提供深层导入,在运行期间,将Ant目标转变为本地Gradle任务。你可以从Gradle中依赖它们,可以从Gradle中提高它们,甚至可以在你的build.xml文件中声明Gradle任务的依赖关系。也为属性、路径等提供了相同的集成……
Gradle fully supports your existing Maven or Ivy repository infrastructure for publishing and retrieving dependencies. Gradle also provides a converter for turning a Maven pom.xml into a Gradle script. Runtime imports of Maven projects will come soon.
Gradle完全支持你现有Maven或Ivy仓库的发布和依赖检索。Gradle还提供将Maven的pom.xml文件转换为Gradle脚本的转换器。将很快支持运行时引入Maven项目。
Ease of migration
可移植
Gradle can adapt to any structure you have. Therefore you can always develop your Gradle build in the same branch where your production build lives and both can evolve in parallel. We usually recommend to write tests that make sure that the produced artifacts are similar. That way migration is as less disruptive and as reliable as possible. This is following the best-practices for refactoring by applying baby steps.
Gradle适用于你拥有的任何结构。因此你总是可以在产品构建的分支上开发你的Gradle构建,两种构建可以并行开发。我们通常要求写相关测试,以保证开发插件的相似性。这种迁移可以减少破坏性和尽可能地可靠。这也是重构的最佳实践。
Groovy
Gradle's build scripts are written in Groovy, not XML. But unlike other approaches this is not for simply exposing the raw scripting power of a dynamic language. That would just lead to a very difficult to maintain build. The whole design of Gradle is oriented towards being used as a language, not as a rigid framework. And Groovy is our glue that allows you to tell your individual story with the abstractions Gradle (or you) provide. Gradle provides some standard stories but they are not privileged in any form. This is for us a major distinguishing feature compared to other declarative build systems. Our Groovy support is not just sugar coating. The whole Gradle API is fully Groovy-ized. Adding Groovy results in an enjoyable and productive experience.
Gradle的构建脚本是用Groovy写的,而不是XML。但与其他方法不同,这并不是简单地公开动态语言的原始脚本编写能力。那只会导致很难保持构建。Gradle整体被设计作为一种语言,而不是一个刚性框架。Groovy是你用Gradle(或你)提供的抽象概念来描述你的想法的粘合剂。Gradle提供了一些标准模块,但这些模块并不是在任何形式下都具有特权。与其他声明性构建系统相比,这是一个主要特点。我们的Groovy支持不仅仅是表面,整个GradleAPI完全Groovy化。将Groovy结果添加到愉快和富有成效的体验中。
The Gradle wrapper
Gradle的封装
The Gradle Wrapper allows you to execute Gradle builds on machines where Gradle is not installed. This is useful for example for some continuous integration servers. It is also useful for an open source project to keep the barrier low for building it. The wrapper is also very interesting for the enterprise. It is a zero administration approach for the client machines. It also enforces the usage of a particular Gradle version thus minimizing support issues.
由于Gradle的封装,Gradle构建的执行不需要安装。这对于一些持续集成服务器来说很有用。对开源项目来说,这有很有用,可以保持低构建屏障。该封装对企业来说也是有益的。对客户机来说,不需要管理员权限。它也强制执行使用一个特定的Gradle版本,从而最小化支持问题。
Free and open source
免费开源
Gradle is an open source project, and is licensed under the ASL.
Gradle是一个开源项目,授权于ASL。
2.2. Why Groovy?
为什么是Groovy?
We think the advantages of an internal DSL (based on a dynamic language) over XML are tremendous when used in build scripts. There are a couple of dynamic languages out there. Why Groovy? The answer lies in the context Gradle is operating in. Although Gradle is a general purpose build tool at its core, its main focus are Java projects. In such projects the team members will be very familiar with Java. We think a build should be as transparent as possible to all team members.
在构建脚本的时候,基于XML的内部DSL(基于动态语言)的有点是巨大的。为什么使用Groovy?答案在于Gradle的运行环境。Gradle虽然是一个通用构建工具的核心,它的主要焦点是Java项目。在这样的项目团队里面,成员将会非常熟悉java。构建应该对所有的项目成员尽可能地透明。
In that case, you might argue why we don't just use Java as the language for build scripts. We think this is a valid question. It would have the highest transparency for your team and the lowest learning curve, but because of the limitations of Java, such a build language would not be as nice, expressive and powerful as it could be. [1] Languages like Python, Groovy or Ruby do a much better job here. We have chosen Groovy as it offers by far the greatest transparency for Java people. Its base syntax is the same as Java's as well as its type system, its package structure and other things. Groovy provides much more on top of that, but with the common foundation of Java.
在这种情况下,你可能会恼火,为什么我们不使用Java语言作为构建脚本语言。我们认为这是一个有效的问题。它可能会为你的团队提供最高的透明度和最低的学习曲线,但是由于Java的局限性,作为一个构建语言,它并非最好的、最优表现力和最有能力的。[1]像Python、Groovy或者Ruby在此会更好。因为Groovy对Java使用者提供了最大透明度,所以我们选择了Groovy。它的基本语法、系统类型结构、package结构和其他都和Java是一样的。Groovy提供了更多的内容,但与Java有着共同的基础。
For Java developers with Python or Ruby knowledge or the desire to learn them, the above arguments don't apply. The Gradle design is well-suited for creating another build script engine in JRuby or Jython. It just doesn't have the highest priority for us at the moment. We happily support any community effort to create additional build script engines.
对拥有Python和Ruby知识(或者有学习Python和Ruby知识欲望)的Java开发者来说,上述论点不适用。Gradle的设计对在JRuby和Jython上创建另外的构建脚本引擎同样适用。目前来说,它并没有给为我们提供最高的优先级。我们乐意支持任何社区创建额外构建脚本引擎的努力。
[1] At http://www.defmacro.org/ramblings/lisp.html you find an interesting article comparing Ant, XML, Java and Lisp. It's funny that the 'if Java had that syntax' syntax in this article is actually the Groovy syntax.
- 【Gradle Build Tool 4.1用户指南】Chapter 2.Overview 第二章、概述
- 【Gradle Build Tool 4.1用户指南】Chapter 5.The Gradle Console
- 【Gradle Build Tool 4.1用户指南】Chapter 6.The Gradle Wrapper
- 【Gradle Build Tool 4.1用户指南】Chapter 3. Installing Gradle 第三章、安装Gradle
- 【Gradle Build Tool 4.1用户指南】Chapter 1. Introduction 第一章、介绍
- 【Gradle Build Tool 4.1用户指南】Chapter 4. Using the Gradle Command-Line 第4章 使用Gradle命令行
- 《gradle 用户指南》中文版 第2章 概述
- 《gradle 用户指南》中文版 第2章 概述
- Gradle第二章:概述
- Gradle--第二章。概述 2.1
- Gradle2.0用户指南翻译——第二章. 概述
- windows环境下安装Gradle Build tool
- Gradle详解-Chapter 16. Writing Build Scripts
- Gradle详解-Chapter 20. The Build Lifecycle
- Gradle 1.12用户指南翻译——第四十七章. Build Init 插件
- Gradle 1.12用户指南翻译——第四十九章. Build Dashboard 插件
- Gradle 1.12用户指南翻译——第二十四章. Groovy 插件
- Gradle 1.12用户指南翻译——第二十五章. Scala 插件
- ubuntu安装mysql Mysql ERROR 1045 (28000): Access denied for user 'root'@'localhost'详细解决办法
- Java日志打印
- List
- android GreenDao3.2 版本示例程序
- [bzoj5039][Jsoi2014]序列维护 线段树
- 【Gradle Build Tool 4.1用户指南】Chapter 2.Overview 第二章、概述
- iOS GCD 学习
- python 1
- DOS命令里面的EQ、NE、GT、LT、GE、LE分别是什么意思
- Unity Shader 之深度测试(ZTest Always Cull Off ZWrite Off)
- 安装pip
- [初学笔记]matlab中怎么判断输入是不是空的, isempty
- 1306:找用户名
- 深入理解 JavaScript 函数的特性与最佳实践