【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、GroovyOSGiWebScala项目的按惯例构建。甚至,这些说明性语言是可扩展的。添加你自己新的语言元素或者提高现有的语言元素,可以提供简洁、易于维护和理解的构建。

 

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.

阅读全文
0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 英语不好又不会读怎么办 七个月宝宝手上长倒刺怎么办 字母纹身纹反了怎么办 花甲生的吃了怎么办 别人告我欠他钱怎么办 实习手册没有公司的印章怎么办? 家长管的太严怎么办 对于老公沉迷于股票怎么办 月经期吃了香瓜怎么办 月经漏到内裤上怎么办 上班没时间养狗怎么办 宝宝呼吸道感染反复发烧怎么办 熬夜后头晕想吐怎么办 生气后全身无力酸痛怎么办? 久坐导致的腰疼怎么办 削土豆手变黑了怎么办 熬夜后头痛眼痛怎么办 孩子毎天通宵游戏怎么办 熬夜写作业困了怎么办 三十多岁白头发越来越多怎么办 AI界面字体太小怎么办 睡不着怎么办躺倒床上脑子混乱 作息规律不正常夜里睡不着怎么办 作息不规律引起身体痒怎么办 在大学里好无聊怎么办 开会时间通知错了怎么办 商场要求商户变更位置怎么办 怀孕初期症状小腹痛怎么办 1岁半宝宝吃夜奶怎么办 戒奶宝宝不喝奶粉怎么办 2岁半宝宝老晚睡怎么办 老是熬夜然后想调生物钟怎么办 一个月宝宝睡眠不好怎么办 个人怎么办一清pos机 社保到退休年龄未交满15年怎么办 退休时社保没交满15时怎么办 单位不支付病假工资怎么办 一年级学生上课注意力不集中怎么办 一年级学生的理解能力差怎么办 一年级学生学习太差怎么办 宝宝屁眼破皮怎么办啊