Gradle 1.12 Translations--nineth groovy high-speed entrance

Source: Internet
Author: User
Tags maven central

Because of the time. No way, take notes and translate at the same time, about Gradle User Guide. This blog is no longer relevant considerations. Only translations and non-translated chapters in this publication.

For other chapter translations please note GitHub this project: https://github.com/msdx/gradledoc/tree/1.12, interview: http://gradledoc.qiniudn.com/1.12/ Userguide/userguide.html

This article is original. Reprint Please specify source: http://blog.csdn.net/maosidiaoxian/article/details/40920093

My translation of Gradle is subject to the project on GitHub and the documentation on http://gradledoc.qiniudn.com.

Where the translation is found to be wrong. will be updated in the above two places first.

Due to time and energy issues, the translation published in the blog is basically not synchronized changes.


Nineth Chapter. Groovy High speed Getting Startedto build a groovy project. You need to useGroovy Plugin。 The plugin extends the Java plug-in and adds groovy's compilation functionality to your project. Your project can include groovy source code, Java source code, or both.

In all other respects. The groovy project is almost the same as the Java project we showed in chapter seventh Java QuickStart .


9.1. A major groovy projectLet's take a look at the example. To use the groovy plugin, you need to include the following in the build script file:

Example 9.1. Groovy Plugin

build.gradle

apply plugin:  ' groovy '  

Note: The code for this sample can be in the Gradle binary file or in the source code.samples/groovy/quickstartSee.

This code will apply the Java plug-in to project at the same time, assuming the Java plugin has not yet been applied. The Groovy plugin inherits compiletasks. In the src/main/groovyfolder to locate the source file, and inherit the compileTesttasks, in src/test/groovyfolder to find the source file of the test. These compilation tasks use federated Compilation of these folders, which means they can include both Java and groovy source files at the same time.

to use groovy to compile the task, You must also declare the groovy version number you want to use and where to get the groovy library.

You can finish by groovy adding dependencies to the configuration. The compile configuration inherits this dependency, so that when compiling groovy and Java source code. The Groovy library is also included in the classpath.

In the following example, we will use the groovy 2.2.0 version number in the MAVEN central repository.

Example 9.2. Dependency on Groovy 2.2.0

build.gradle

repositories {    mavencentral ()}dependencies {    ' org.codehaus.groovy:groovy-all:2.2.0 '}

Here is the build file we wrote:

Example 9.3. Groovy Example-complete Build File

build.gradle

Apply plugin:' Eclipse 'Apply plugin:' Groovy 'repositories {mavencentral ()}dependencies {compile' org.codehaus.groovy:groovy-all:2.2.0 'Testcompile' junit:junit:4.11 '}

Execution gradle build will compile your project. Test and hit into a jar package.

9.2. SummaryThis chapter describes a very easy groovy project. Typically, a real project requires more than that. Because a groovy project also is aA Java project, because Groovyproject is also a javaproject, so you can do things with Java that groovy can do.


you can read   24th chapter   Groovy Plug-ins   Get to know a lot of other things about groovy plugins, or   in the Gradle release package, samples/groovy   folder, found many other groovy demo sample projects.

Gradle 1.12 Translations--nineth groovy high-speed entry

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.