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.