转载地址: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快速入门的更多相关文章

  1. Gradle 1.12 翻译——第九章 Groovy快速入门

    由于时间关系,没办法同时做笔记和翻译,关于Gradle的用户指南,本博客不再做相关笔记,而只对未翻译章节进行翻译并在此发表. 有关其他已翻译的章节请关注Github上的项目:https://githu ...

  2. Gradle 1.12 翻译——第九章 Groovy高速入口

    由于时间.没办法,做笔记和翻译的同时,大约Gradle用户指南.本博客不再做相关的注意事项.而仅仅翻译和本出版物中未翻译章节. 有关其他章节翻译请注意Github该项目:https://github. ...

  3. Gradle用户指南(章9:Groovy快速入门)

    Gradle用户指南(章9:Groovy快速入门) 你可以使用groovy插件来构建groovy项目.这个插件继承了java插件的功能,且扩展了groovy编译.你的项目可以包含groovy代码.ja ...

  4. 大数据技术之_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 ...

  5. 【转】MyBatis学习总结(一)——MyBatis快速入门

    [转]MyBatis学习总结(一)——MyBatis快速入门 一.Mybatis介绍 MyBatis是一个支持普通SQL查询,存储过程和高级映射的优秀持久层框架.MyBatis消除了几乎所有的JDBC ...

  6. MyBatis学习总结(一)——MyBatis快速入门(转载)

    本文转载自http://www.cnblogs.com/jpf-java/p/6013537.html MyBatis是一个支持普通SQL查询,存储过程和高级映射的优秀持久层框架.MyBatis消除了 ...

  7. JavaScript学习02(js快速入门)

    快速入门 基本语法 JavaScript的语法和Java的语法类似,每个语句以;结束,语句块用{...}.但是JavaScrip并不强制要求在每个语句的结尾加;,浏览器中负责执行JavaScript代 ...

  8. MyBatis学习总结(一)——MyBatis快速入门

    一.Mybatis介绍 MyBatis是一个支持普通SQL查询,存储过程和高级映射的优秀持久层框架.MyBatis消除了几乎所有的JDBC代码和参数的手工设置以及对结果集的检索封装.MyBatis可以 ...

  9. 【Python】【学习笔记】1.快速入门

    1.软件安装 从官网下载相应版本的安装包,一般不大. https://www.python.org/ 安装一路默认即可 2. 参考教程:快速入门:十分钟学会Python 本文的内容介于教程(Totur ...

随机推荐

  1. python字典基本操作

    字典是python中五中基本数据类型之一,虽然它的赋值稍微麻烦点,但用起来真的是很方便.它用键值对来存放数据,所谓键值对,就是一个键,对应一个值,如果后面对前面的键再次赋值,第一次的值就被覆盖掉.像是 ...

  2. CF261E Maxim and Calculator

    CF261E Maxim and Calculator 洛谷评测传送门 题目描述 Maxim has got a calculator. The calculator has two integer ...

  3. Oracle工具PLSQL

    2018版的PLSQL美化工具在Tools中的PL/SQL Beautifier中 如下:

  4. IntelliJ idea 创建Web项目后web文件夹下没有WEB-INF的解决方法

    1.Ctrl+Shift+Alt+S快捷键进入Project structure(项目结构)管理的界面 2.选择左边菜单栏里的Facet,点击后能看到有Deployment Descriptors的输 ...

  5. windows下sed回车换行符处理

    windows下sed回车换行符处理如果用sed for windows对整个文件进行了编辑,编辑之后一般需要处理回车换行符:rem windows的回车换行符是\r\n,linux的是\n,所以要替 ...

  6. [LeetCode] 419. Battleships in a Board 平板上的战船

    Given an 2D board, count how many battleships are in it. The battleships are represented with 'X's, ...

  7. [LeetCode] 272. Closest Binary Search Tree Value II 最近的二分搜索树的值之二

    Given a non-empty binary search tree and a target value, find k values in the BST that are closest t ...

  8. DVWA XSS (Stored) 通关教程

    Stored Cross Site Scripting 存储型XSS,持久化,代码是存储在服务器中的,如在个人信息或发表文章等地方,加入代码,如果没有过滤或过滤不严,那么这些代码将储存到服务器中,用户 ...

  9. Spring Boot 知识笔记(定时任务与异步)

    一.定时任务 1.启动类里面增加注入 @SpringBootApplication //@SpringBootApplication = @Configuration+@EnableAutoConfi ...

  10. 编程哲理小故事:Tina的运动会方阵

    自从接到任务后,Tina一直 烦恼着如何让这群繁忙又缺乏才艺的程序员在运动会开幕式上做出一个有趣的方阵表演. 接到了运动会的方阵表演的任务 时间回到1个月前. Tina正在工位上繁忙地进行着下一期准备 ...