Gradle is a great build language. To use gradle for our project we can download the Gradle distribution and install it on our machine. But maybe we want to share our project with other people that don't have Gradle installed. Or suppose we use a continuous integration server without native Gradle support, but with support to run command-line commands. Then we can use the Gradle wrapper. The wrapper is responsible for downloading the Gradle distribution and making it available for our project.
To enable the Gradle wrapper for our project we first add a new task to our build.gradle
:
// File: build.gradle task createWrapper(type: Wrapper) { gradleVersion = '0.9-preview-1' }
Next we run $ gradle createWrapper
and when the process is finished we take a look at the project directory and see the following new files:
gradle-wrapper.jar gradle-wrapper.properties gradlew gradlew.bat
Now we only have to distribute this files with our project. Now anyone can run $ gradlew
to execute the tasks defined in the Gradle build file. If Gradle hasn't been installed yet, it will be downloaded and installed for the user and the task is executed!
More information is available in the Gradle User Guide.