Gangmax Blog

Gradle Wrapper

From here.

The Gradle wrapper is some files(bash/bat/jar/properties) created by the “gradle wrapper” command with which a user can run the scripts(bash/bat) to perform all the Gradle command operations without installing Gradle in the environment. All the files are supposed to commit into VCS like Git. Using the Gradle wrapper has the following 2 benefits:

  1. No need to install Gradle before building a Gradle project;

  2. Make the building process use the exact Gradle version as the Gradle project author wanted.

To run the Gradle wrapper:

1
2
3
4
# For Unix like OS.
./gradlew build # Any valid Gradle command arguments can be used as "build" here.
# For Windows.
.\gradlew.bat build

When you use the Gradle wrapper to perform Gradle operations, the script will download the specific version of Gradle package file first if it didn’t, install it to the “$USER_HOME/.gradle/wrapper/dists” directory, then execute the command.

To generate the Gradle wrapper for your Gradle project, you just need to run the following command under your Gradle project directory:

1
2
3
4
5
6
7
8
gradle wrapper
# The following files are generated after the command executed:
your_project/
gradlew
gradlew.bat
gradle/wrapper/
gradle-wrapper.jar
gradle-wrapper.properties

You can specify the Gradle version you want the Gradle wrapper use:

1
gradle wrapper --gradle-version 2.3

If no version is given like in the earlier case, by default the Gradle version in your environment is used.

There are also some properties in the “gradle-wrapper.properties” file you can updated, such as the “distributionUrl” property which is used for the Gradle wrapper script to download the Gradle package file. More information can be found in the offical document.

Comments