Difference between using gradlew and gradle
Asked Answered
D

2

346

What is the difference between using gradlew and gradle or are they the same?

Detriment answered 21/9, 2016 at 21:59 Comment(0)
P
333

The difference lies in the fact that ./gradlew indicates you are using a gradle wrapper. The wrapper is generally part of a project and it facilitates installation of gradle. If you were using gradle without the wrapper you would have to manually install it - for example, on a mac brew install gradle and then invoke gradle using the gradle command. In both cases you are using gradle, but the former is more convenient and ensures version consistency across different machines.

Each Wrapper is tied to a specific version of Gradle, so when you first run one of the commands above for a given Gradle version, it will download the corresponding Gradle distribution and use it to execute the build.

Not only does this mean that you don’t have to manually install Gradle yourself, but you are also sure to use the version of Gradle that the build is designed for. This makes your historical builds more reliable

Read more here - https://docs.gradle.org/current/userguide/gradle_wrapper.html

Also, Udacity has a neat, high level video explaining the concept of the gradle wrapper - https://www.youtube.com/watch?v=1aA949H-shk

Paniagua answered 21/9, 2016 at 22:17 Comment(4)
Maybe I'm reading it wrong but sounds like a red flag to me. It sounds like Gradle is not backward compatible, or it's evolving very fast (and unstable). What happens with CI servers that do not have access to the internet?Jutland
@TheImpaler I guess you have to install all the required versions of Gradle as the Wrapper would if it had Internet access.Lewanna
so a one-liner conclusion might be: always prefer ./gradlew build over gradle build right?Delfinadelfine
@Delfinadelfine correct, you don't even have to specify the build part as clean and build is the Default tasks, when you execute ./gradlewFatimafatimah
P
107

gradle vs gradlew

gradlew is a wrapper(w - character) that uses gradle.

Under the hood gradlew performs three main things:

  • Download and install the correct gradle version
  • Parse the arguments
  • Call a gradle task

Using Gradle Wrapper we can distribute/share a project to everybody to use the same version and Gradle's functionality(compile, build, install...) even if it has not been installed.

To create a wrapper run:

gradle wrapper

This command generate:

gradle-wrapper.properties will contain the information about the Gradle distribution

*./ Is used on Unix to specify the current directory

Parkway answered 2/3, 2018 at 20:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.