Gradle Wrapper
Estimated time to read: 2 minutes
Overview¶
The Gradle wrapper defines a specific version of Gradle to be used with the project, which in turn enables consistent builds across machines.
IDE's rely on the Gradle wrapper when loading a project to ensure that the correct version of Gradle is in use.
Build Servers also rely on the Gradle wrapper. If the build server does not have Gradle installed, then it will use the wrapper provided.
Creation¶
The gradle wrapper
command exports a wrapper for Gradle to the project structure. Multiple files are exported during this process:
- <project>
- gradlew // macOS / UNIX platforms
- gradlew.bat // Windows platforms
- gradle
- wrapper
- gradle-wrapper.jar
- gradle-wrapper.properties
Initialisation¶
Once a wrapper has been generated, it can be initialised in two ways:
- By running
./gradlew build
, this stores a specific version of Gradle on the system, typically in~/.gradle/wrapper/dists/
, which is independent from the system-wide installed version of Gradle. - By running
gradle build
. When the systems'gradle
binary is run from the command line, it will detect if the wrapper has been added to a project, if it does, then the version of Gradle defined in the the wrapper is used rather than the systems' version.
Configuration Flags¶
--gradle-version x.y
can be used to set the version of the Gradle wrapper to a specific version --distribution-type xxx
can be used to specify a distribution type. By default, the wrapper will download bin
.
Using a Build Server¶
Builds servers are used for Continuous Integration; whenever a change to the code is made, it is automatically compiled by the server and tested, if configured to do so, and Nightly Builds; where codes is built each night.
If neither of the above are suitable for the current project, then a build server, at a bare minimum, ensures that a system is available to produce a clean build, where the code is built within a known 'good' environment.
Build Server Products¶
- TeamCity by JetBrains
- Will add more here soon
Configuring the Build Server¶
This is dependant on the build server product in use. For TeamCity, JetBrains provided extensive documentation on their site