Gradle Introductory Demo

Source: Internet
Author: User

Gradle Introductory Demo

Installation configuration omitted

New Gradle project in Idea name: Gradle-showcase

?  gradle-showcase  gradle  -v------------------------------------------------------------gradle 2.6--------------------------- ---------------------------------Build time:   2015-08-10 13:15:06 utcbuild  number: nonerevision:     233bbf8e47c82f72cb898b3e0a96b85d0aad166egroovy:        2.3.10Ant:           apache ant (TM)  VERSION 1.9.3 COMPILED ON DECEMBER 23 2013JVM:           1.8.0_51  (oracle corporation 25.51- B03) os:           mac os x 10.10.5  x86_64?  gradle-showcase  type gradlegradle is /users/xinxingegeya/ide/ Gradle-2.6/bin/gradle 

The installation was successful.


Gradle Task

Write the first task in the Build.gradle file, as below,

Task HelloWorld () {dolast {println ' Hello World '}}

Run task,

? Gradle-showcase gradle-q Helloworldhello World

Tasks are written in a variety of ways, such as shorthand, using << to define the body of a task,

Task Helloworldbyshortcut << {println ' Hello World '}

There are also the following tasks,

Task Upper << {String somestring = ' my_name ' println "Original:" + somestring println "upper case:" + so Mestring.touppercase ()}task count << {4.times {print "$it"}}

These task definitions use groovy's code and method calls and, of course, groovy closures. Before you learn gradle, you should look at the usage of groovy closures, and the closure of groovy is not quite the same as in other languages.


Gradle Task Dependencies

Gradle tasks can be mutually dependent. While defining a task, you can declare task-dependent tasks, such as the following,

Task Hello << {println ' Hello world! '} Task Intro (Dependson:hello) << {println "I ' m Gradle"}

Task intro relies on the Hello task. When you run intro, the Hello task also executes. As follows

? Gradle-showcase gradle-q Introhello world! I ' m Gradle

When the Hello task does not exist, the intro task is executed with an error, as follows,

* What went wrong:a problem occurred evaluating root project ' gradle-showcase ' .> Could not find property ' hello ' on roo T project ' Gradle-showcase '.

Is there any way to solve the task of being relied upon without the times being wrong? You can declare and define a task like this,

Task Taskx (dependsOn: ' Tasky ') << {println ' taskx '}task Tasky << {println ' Tasky '}

Run task,

? Gradle-showcase Gradle-q taskxtaskytaskx

At this time Tasky is not exist and will not affect taskx.

======end======

Gradle Introductory Demo

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.