Gradle Wrapper
Gradle Wrapper
The Gradle Wrapper is a way to ensure a project can be built with a specific version of Gradle, without requiring users to install Gradle manually. It acts as a “wrapper” script around Gradle, letting developers build projects consistently, even if they don’t have Gradle installed.
The Gradle Wrapper is a script that allows a project to build with a fixed Gradle version. It consists of files like gradlew
, gradlew.bat
, and the gradle/wrapper
directory containing wrapper JAR and properties files.
- Includes a
gradle-wrapper.properties
file to specify the Gradle version and distribution URL. - Automatically downloads and uses the declared Gradle version for the project.
Wrapper script
The wrapper script file for Linux and Windows operating system are as follows:
Operating System | Wrapper Script |
---|---|
Linux/macOS | gradlew (Shell script) |
Windows | gradlew.bat (Batch file) |
The Gradle Wrapper consists of scripts (named gradlew
for Unix-based systems and gradlew.bat
for Windows) that execute a predefined version of Gradle, automatically downloading it if it is not already available. Rather than relying on a locally installed Gradle instance and running gradle build
, you can use the Wrapper by executing ./gradlew build
(or gradlew.bat build
on Windows), ensuring the declared Gradle version is used consistently.
It is useful in Continuous Integration (CI) environments where the Gradle version must be consistent. The wrapper can be generated using the command: gradle wrapper
.
Advantages
Some of the advantages of Gradle wrapper are as follows:
- Version Consistency: Ensures everyone uses the same Gradle version across all environments.
- No Pre-installation Needed: Users do not need to install Gradle manually. The wrapper downloads it automatically. Downloads and caches Gradle automatically, saving time and effort.
- Better Automation: Simplifies scripting and automation in build pipelines and CI/CD tools.
- Project Portability: Developers can clone the repository and build the project immediately with no setup hassle.
- Ease of Use: Using
./gradlew
orgradlew.bat
makes running Gradle commands straightforward for all users. - Cross-Platform Compatibility: Works seamlessly across Windows, macOS, and Linux.