• gradlew is a wrapper
  • A wrapper is a script that invokes a declared version of Gradle, downloading it beforehand if necessary

When building projects on a cloud, use ./gradlew over gradle

The former command executes an existing file while the later is a call to an executable that should have to been already installed and configured.


Adding the wrapper

  • If you have a Gradle project that doesn’t already have a wrapper, you can add the wrapper
  • Every vanilla Gradle build comes with a built-in task calledΒ wrapper
  • Run gradle wrapper to generate the necessary wrapper files
  • Generated files,
    • gradle-wrapper.jar - JAR file containing code for downloading the Gradle distribution
    • gradle-wrapper.properties - wrapper config
    • gradlew - a shell script to execute the build with the wrapper
    • gradlew.bat - a windows batch script to execute the build with the wrapper
  • The generated wrapper will reside within the gradle directory in the project’s root
    β”œβ”€β”€ a-subproject
    β”‚   └── build.gradle.kts
    β”œβ”€β”€ settings.gradle.kts
    β”œβ”€β”€ gradle
    β”‚   └── wrapper
    β”‚       β”œβ”€β”€ gradle-wrapper.jar
    β”‚       └── gradle-wrapper.properties
    β”œβ”€β”€ gradlew
    └── gradlew.bat
    

Wrapper definition

Found in gradle/wrapper/gradle-wrapper.properties,

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
  • Changing the Gradle version of a project is now a simple change in the wrapper definition. It can even be made by running ./gradlew wrapper --gradle-version 8.3

Refs

  1. https://stackoverflow.com/questions/39627231/difference-between-using-gradlew-and-gradle
  2. https://docs.gradle.org/current/userguide/gradle_wrapper.html#:~:text=The%20Wrapper%20is%20a%20script,more%20reliable%20and%20robust%20builds.