【转载】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 ...
随机推荐
- 解决Android中AsyncTask的多线程阻塞问题
Android开发中执行耗时操作并更新UI时,通常有三种方式:1.直接调用runOnUiThread(new Runnable(){}),使用简单,但不能在Activity之外的环境使用,如View. ...
- 18-numpy笔记-莫烦pandas-6-plot显示
代码 import pandas as pd import numpy as np import matplotlib.pyplot as plt data = pd.Series(np.random ...
- 01-人脸识别-基于MTCNN,框选人脸区域-detect_face_main
(本系列随笔持续更新) 搭建要求 详细的搭建过程在 参考资料1 中已经有啦. TensorFlow 1.6.0 OpenCV 2.4.8 仅仅是加载和读取图片的需要 Ubuntu 14.04 64bi ...
- Python进阶-XII serialize(序列化)、序列化模块
一.serialize 序列化 1.什么叫序列化——将原本的字典.列表等内容转换成一个字符串的过程就叫做序列化. 比如,我们在python代码中计算的一个数据需要给另外一段程序使用,那我们怎么给?现在 ...
- odoo 新建模块命令
python odoo-bin scaffold academy myaddons 自动初始化所有的配置信息: python odoo-bin --addons=addons,"/home/ ...
- 使用arthas 生成火焰图分析jvm
arthas 是阿里巴巴开源的强大的jvm 应该分析工具,以下是使用arthas 生成jvm 火焰图的一个学习 项目使用docker-compose 运行,对于生成的火焰图使用nginx 提供一个访问 ...
- [LeetCode] 632. Smallest Range Covering Elements from K Lists 覆盖K个列表元素的最小区间
You have k lists of sorted integers in ascending order. Find the smallest range that includes at lea ...
- IDCode校验算法
运行地址: https://c.runoob.com/compile/10 算法源码 public class HelloWorld { public static void main(String ...
- laravel5.5框架中视图间如何共享数据?视图间共享数据的两种方法
laravel框架中视图间共享数据有两种,一种是用视图门面share()方法实现,另一种是用视图门面composer() 方法实现,那么,两种方法的实现究竟是怎样的呢?让我们来看一看接下来的文章内容. ...
- POSIX 正则表达式 BRE与ERE的差异
BRE,标准正则表达式,basic regular expressions ERE,扩展正则表达式,Extended Regular Expressions POSIX 正则表达式 传统上,POSIX ...