【转载】Gradle学习 第九章:Groovy快速入门
转载地址:http://ask.android-studio.org/?/article/17
To build a Groovy project, you use the Groovy plugin. This plugin extends the Java plugin to add Groovy compilation capabilities to your project. Your project can contain Groovy source code, Java source code, or a mix of the two. In every other respect, a Groovy project is identical to a Java project, which we have already seen in Chapter 7, Java Quickstart.
<翻译>想要构建一个Groovy项目,你需要用到Groovy插件。这个插件继承自Java插件以便添加Groovy编译能力到你的项目中。你的项目可以包含Groovy源码,Java源码,或者是二者混合使用。在其他所以方面,一个Groovy项目与Java项目相同,这一点我们在第七章,Java快速入门里就已经看到了。
9.1. A basic Groovy project 一个基本的Groovy工程
Let's look at an example. To use the Groovy plugin, add the following to your build file:
<翻译>接下来让我们看一个例子。想要使用Groovy插件就添加如下代码到你的构建文件中:
Example 9.1. Groovy plugin Groovy插件
build.gradle
apply plugin: 'groovy'
Note: The code for this example can be found at samples/groovy/quickstart which is in both the binary and source distributions of Gradle.
注意:这个例子中代码可以在samples/groovy/quickstart目录下找到。
This will also apply the Java plugin to the project, if it has not already been applied. The Groovy plugin extends the compile task to look for source files in directory src/main/groovy, and the compileTest task to look for test source files in directory src/test/groovy. The compile tasks use joint compilation for these directories, which means they can contain a mixture of Java and Groovy source files.
<翻译>如果Java插件还没有被加入,那么这段代码同样也会将Java插件加入到项目中。Groovy插件继承了compile task以便从src/main/groovy目录中搜索源码文件,继承了compileTest task以便从src/test/groovy目录中搜索测试源码文件。compile tasks对这些目录使用了联合编译,这意味着他们可以混合Java和Groovy文件。
To use the Groovy compilation tasks, you must also declare the Groovy version to use and where to find the Groovy libraries. You do this by adding a dependency to the groovy configuration. The compile configuration inherits this dependency, so the Groovy libraries will be included in classpath when compiling Groovy and Java source. For our sample, we will use Groovy 2.2.0 from the public Maven repository:
<翻译>想要使用Groovy编译任务,你必须声明Groovy版本和在哪里能够找到Groovy库文件,你可以通过在Groovy配置项中添加依赖来完成这两项工作。编译配置项继承了该依赖声明,所以当编译Groovy和Java源码时Groovy库文件会被包含到classpath中。在我们的示例中,我们将会使用来自公共Maven仓库的Groovy 2.2.0(我觉得这里版本号写错了,因为根据下面的示例,版本应该是2.3.6):
Example 9.2. Dependency on Groovy Groovy依赖
build.gradle
repositories {
mavenCentral()
}
dependencies {
compile 'org.codehaus.groovy:groovy-all:2.3.6'
}
Here is our complete build file:
<翻译>下面是完整的脚本构建文件:
Example 9.3. Groovy example - complete build file Groovy示例 - 完整的构建文件
build.gradle
apply plugin: 'eclipse'
apply plugin: 'groovy'
repositories {
mavenCentral()
}
dependencies {
compile 'org.codehaus.groovy:groovy-all:2.3.6'
testCompile 'junit:junit:4.11'
}
Running gradle build will compile, test and JAR your project.
<翻译>运行命令gradle build将会编译、测试并打包你的项目。
9.2. Summary
This chapter describes a very simple Groovy project. Usually, a real project will require more than this. Because a Groovy project is a Java project, whatever you can do with a Java project, you can also do with a Groovy project.
<翻译>本章叙述了一个非常简单的Groovy项目。通常情况下,一个实际项目要求的会比这个示例项目多。因为一个Groovy项目就是一个Java项目,任何你可以用Java项目做的,你也可以用Groovy项目完成。
You can find out more about the Groovy plugin in Chapter 24, The Groovy Plugin, and you can find more sample Groovy projects in the samples/groovy directory in the Gradle distribution.
<翻译>在24章,Groovy插件中你可以找到更多有关Groovy插件的信息,并且你可以在Gradle安装目录目录下的samples/groovy目录中找到更多的Groovy项目示例。
原文地址:http://www.gradle.org/docs/cur ... .html
翻译者:Jerry
邮箱:hjpdyxhjd@163.com
如对翻译内容有异议,请在评论区提出或联系作者
【转载】Gradle学习 第九章:Groovy快速入门的更多相关文章
- Gradle 1.12 翻译——第九章 Groovy快速入门
由于时间关系,没办法同时做笔记和翻译,关于Gradle的用户指南,本博客不再做相关笔记,而只对未翻译章节进行翻译并在此发表. 有关其他已翻译的章节请关注Github上的项目:https://githu ...
- Gradle 1.12 翻译——第九章 Groovy高速入口
由于时间.没办法,做笔记和翻译的同时,大约Gradle用户指南.本博客不再做相关的注意事项.而仅仅翻译和本出版物中未翻译章节. 有关其他章节翻译请注意Github该项目:https://github. ...
- Gradle用户指南(章9:Groovy快速入门)
Gradle用户指南(章9:Groovy快速入门) 你可以使用groovy插件来构建groovy项目.这个插件继承了java插件的功能,且扩展了groovy编译.你的项目可以包含groovy代码.ja ...
- 大数据技术之_09_Flume学习_Flume概述+Flume快速入门+Flume企业开发案例+Flume监控之Ganglia+Flume高级之自定义MySQLSource+Flume企业真实面试题(重点)
第1章 Flume概述1.1 Flume定义1.2 Flume组成架构1.2.1 Agent1.2.2 Source1.2.3 Channel1.2.4 Sink1.2.5 Event1.3 Flum ...
- 【转】MyBatis学习总结(一)——MyBatis快速入门
[转]MyBatis学习总结(一)——MyBatis快速入门 一.Mybatis介绍 MyBatis是一个支持普通SQL查询,存储过程和高级映射的优秀持久层框架.MyBatis消除了几乎所有的JDBC ...
- MyBatis学习总结(一)——MyBatis快速入门(转载)
本文转载自http://www.cnblogs.com/jpf-java/p/6013537.html MyBatis是一个支持普通SQL查询,存储过程和高级映射的优秀持久层框架.MyBatis消除了 ...
- JavaScript学习02(js快速入门)
快速入门 基本语法 JavaScript的语法和Java的语法类似,每个语句以;结束,语句块用{...}.但是JavaScrip并不强制要求在每个语句的结尾加;,浏览器中负责执行JavaScript代 ...
- MyBatis学习总结(一)——MyBatis快速入门
一.Mybatis介绍 MyBatis是一个支持普通SQL查询,存储过程和高级映射的优秀持久层框架.MyBatis消除了几乎所有的JDBC代码和参数的手工设置以及对结果集的检索封装.MyBatis可以 ...
- 【Python】【学习笔记】1.快速入门
1.软件安装 从官网下载相应版本的安装包,一般不大. https://www.python.org/ 安装一路默认即可 2. 参考教程:快速入门:十分钟学会Python 本文的内容介于教程(Totur ...
随机推荐
- 洛谷 P1182 数列分段 Section II
洛谷 P1182 数列分段 Section II 洛谷传送门 题目描述 对于给定的一个长度为N的正整数数列A-iA−i,现要将其分成M(M≤N)M(M≤N)段,并要求每段连续,且每段和的最大值最小. ...
- Sublime Text 3安装GoSublime
GoLand IDE工具虽然在编程时很好用,但是在使用中也有个问题,有时我们可能只是写一个简单的脚本来测试,对于我而言在打开IDE太重量级了,所以捣鼓了GoSublime工具来满足平时最基本的需求 ...
- openlayers绘制点,线,圆等
由于我的业务需求是可以在底图上进行一些操作,比如绘制电子围栏等功能,于是需要使用openlayers中的画笔功能,接下来开始一波操作 还是上一篇的html页面, 直接上代码 <!doctype ...
- nwjs-打包
1: 将项目内所有文件压缩成一个压缩包 app.zip 2: 将压缩包重命名为 app.nw 3: 将压缩包放置到 下载解压后的 nw.js 根目录下 4: shift+鼠标右键 选择在此处打开命令窗 ...
- 生成指定python项目中所有的依赖文件
一. pipreqs工具 这个工具的好处是可以通过对项目目录的扫描,自动发现使用了那些类库,自动生成依赖清单. 缺点是可能会有些偏差,需要检查并自己调整下. 安装: pip install pipre ...
- [BJOI2019]奥术神杖(AC自动机,DP,分数规划)
题目大意: 给出一个长度 $n$ 的字符串 $T$,只由数字和点组成.你可以把每个点替换成一个任意的数字.再给出 $m$ 个数字串 $S_i$,第 $i$ 个权值为 $t_i$. 对于一个替换方案,这 ...
- [LeetCode] 208. Implement Trie (Prefix Tree) 实现字典树(前缀树)
Implement a trie with insert, search, and startsWith methods. Example: Trie trie = new Trie(); trie. ...
- [LeetCode] 15. 3Sum 三数之和
Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all un ...
- spring cloud gateway 全局过滤器
全局过滤器作用于所有的路由,不需要单独配置,我们可以用它来实现很多统一化处理的业务需求,比如权限认证,IP访问限制等等. 接口定义类:org.springframework.cloud.gateway ...
- 第26课 std::async异步任务
一. std::async函数模板 (一)std::async和std::thread的区别 1. 两者最明显的区别在于async采用默认启动策略时并不一定创建新的线程.如果系统资源紧张,那么std: ...