gradle-wrapper.properties


Overview

The `gradle-wrapper.properties` file is a configuration file used by the Gradle Wrapper, a mechanism that allows a project to be built with a specific Gradle version, regardless of what is installed on the developer's machine or CI environment. This file specifies the details required to download and use the designated Gradle distribution automatically.

The primary purpose of this file is to ensure build consistency across different machines and environments by locking the Gradle version and defining where and how the Gradle distribution is stored and retrieved.


File Structure and Properties

This file contains key-value pairs that define the configuration for the Gradle Wrapper. Each property affects how the wrapper behaves during build initialization.

Properties

Property Name

Description

Example Value

`distributionBase`

Defines the base directory where the Gradle distribution is stored or cached. Typically a special directory like [GRADLE_USER_HOME](/projects/288/68303) or `PROJECT`.

GRADLE_USER_HOME

`distributionPath`

Specifies the path relative to the base directory where the distribution is unpacked.

`wrapper/dists`

`zipStoreBase`

Defines the base directory where the downloaded Gradle distribution ZIP files are stored.

GRADLE_USER_HOME

`zipStorePath`

Specifies the path relative to the zip store base directory for saving the ZIP files of Gradle distributions.

`wrapper/dists`

`distributionUrl`

The URL from which the Gradle distribution ZIP is downloaded. This URL determines the Gradle version and distribution type (all, bin, etc.).

`https\://services.gradle.org/distributions/gradle-4.4-all.zip`


Detailed Explanation of Each Property

1. distributionBase

2. distributionPath

3. zipStoreBase

4. zipStorePath

5. distributionUrl


Usage Example

When a developer runs `./gradlew build` (Unix) or `gradlew.bat build` (Windows), the Gradle Wrapper:

  1. Reads the gradle-wrapper.properties file.

  2. Checks if the specified Gradle version is already downloaded and unpacked in the specified directories.

  3. If not present, downloads the Gradle ZIP from the distributionUrl.

  4. Unpacks and caches the Gradle distribution.

  5. Executes the build using that Gradle version.

This process ensures that every user, CI pipeline, or environment uses exactly the same Gradle version without manual installation.


Important Implementation Details


Interaction with Other Parts of the System


Visual Diagram: Gradle Wrapper Workflow Using gradle-wrapper.properties

flowchart TD
    A[User runs ./gradlew or gradlew.bat] --> B[gradle-wrapper.properties Read]
    B --> C{Is Gradle distribution cached?}
    C -- Yes --> D[Use cached Gradle distribution]
    C -- No --> E[Download Gradle ZIP from distributionUrl]
    E --> F[Save ZIP to zipStoreBase/zipStorePath]
    F --> G[Unpack ZIP to distributionBase/distributionPath]
    G --> D
    D --> H[Execute Gradle build with specified version]

Summary

The `gradle-wrapper.properties` file is a lightweight, yet critical configuration file that ensures consistent Gradle usage across environments by specifying the distribution's location, caching strategy, and exact version URL. It works hand-in-hand with Gradle Wrapper scripts and the wrapper JAR to automate Gradle setup and execution seamlessly, promoting reliable and reproducible builds in development and CI/CD workflows.