Difference between using gradlew and gradle

Gradle tasks are run with either the gradle or gradlew commands.

Gradlew is a gradle wrapper for the gradle command.

This tutorial talks about the difference between gradlew and gradle command.

What you can do with Gradle command?

if your machine has a gradle installation, Then the gradle command works as seen below.

It gives Gradle version installed on a local machine.

C:\>gradle

> Task :help

Welcome to Gradle 6.0.1.

To run a build, run Gradle <task> ...

To see a list of available tasks, run Gradle tasks

To see a list of command-line options, run gradle --help

To see more detail about a task, run gradle help --task <task>

For troubleshooting, visit https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.0.1/userguide/command_line_interface.html#sec:command_line_warnings

BUILD SUCCESSFUL in 1s
1 actionable task: 1 executed

Gradle installed on a local machine, you can do the following things.

  • You can create a new project using the below command
gradle init

It creates a new project by asking for input from users on the type of project, build a script

B:\kiranw>gradle init

Select the type of project to generate:
  1: basic
  2: application
  3: library
  4: Gradle plugin
Enter selection (default: basic) [1..4]


Select build script DSL:
  1: Groovy
  2: Kotlin
Enter selection (default: Groovy) [1..2]

Project name (default: kiranw):

> Task :init
Get more help with your project: https://guides.gradle.org/creating-new-gradle-builds.

BUILD SUCCESSFUL in 1m 4s
2 actionable tasks: 2 executed
  • You can add a wrapper with the gradle command to the project
gradle wrapper --gradle-version 7.1.1
  • You can run a list of the tasks of a Gradle
gradle tasks
  • you can run build or test the project using the below command
gradle test
gradle build

Gradle wrapper

The gradle wrapper command is run by using ./gradlew command in Linux and gradlew in windows. gradle wrapper can be added using the below command

gradle wrapper --gradle-version 7.1.1

It is part of a Gradle project with a specific version installed.

It does the following things in a project.

  • Checks whether Gradle exists or not, if not inline installation with the correct Gradle version
  • Call gradle tasks

gradle-wrapper.properties contain the gradle wrapper configuration information

gradle wrapper commands add the wrapper to the gradle project and the following is a project structure.

└── <project folder>
    └── gradlew
    └── gradlew.bat
    └── build.gradle
    └──
    └──
    └── gradle
        └── wrapper
            └── gradle-wrapper.jar
            └── gradle-wrapper.properties

Comparision of gradle and gradlew commands

Gradlewgradlew
Installation and running is manualGradle installation is by default do it
Local machine with single versionEach project can be configured different version
Local installation is requiredNo local installation is required
All the tasks can be run with this commandExcept initialization of the project, all other tasks can be executed
build, test, init, wrapper, and any native tasksinit and wrapper tasks will not work, other build, test, and native tasks works
gradle setup will not configure to repositoryAlways the good way is to commit wrapper files to repository

Conclusion

In this tutorial, Learned the difference between gradlew and gradle command.

Both are the same and equal except initializing and adding a wrapper is not possible with a Gradle wrapper.