The use of Gradle wrapper

Source: Internet
Author: User
Tags wrapper

When we usually use Gradle to build the project, we can install the Gradle on the computer now, after configuring the environment variable, we can use it normally.

But when we share the project with a person who does not have Gradle installed on a computer, the overall project construction needs to be configured to look troublesome.

This leads to today's protagonist: Gradle wrapper a Gradle package, even if the computer is not installed Gradle can be built.


To use Gradle wrapper, you first want to create it in your project. Specifically, add a task similar to the following in Build.gradle:

File:build.gradle
Task CreateWrapper (type:wrapper) {
    gradleversion = ' 0.9-preview-1 '
}

Of course, the version should be filled in.



Then execute:

Gradle CreateWrapper




The following directory structure is generated under the directory

project-name/
  gradlew
  gradlew.bat
  gradle/wrapper/
    Gradle-wrapper.jar
    Gradle-wrapper.properties





These files make up the Gradle wrapper, and generating Gradle wrapper only needs to be done once


Use

When we need to use Gradle wrapper, we directly execute the Gradlew (Gradle wrapper shorthand) directly in the project root directory, using Gradlew in exactly the same way as gradle, for example, through Gradlew Tasks to see all of them. In fact, when executing the Gradlew command, Gradlew will entrust the Gradle command to do the corresponding thing, so Gradlew really is just a shell.

When the Gradlew is executed, wrapper checks whether the current machine has a corresponding version of Gradle installed, and if so, Gradlew delegates the command to execute the user input. If it's not installed, it will automatically download the installation from Gradle repository first. Of course, you can also specify the server you want to download in the configuration file instead of the default Gradle repo.



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.