English

Adding Gradle Wrapper to an existing project

This quick tutorial will show the few steps for adding Gradle Wrapper to an existing project, in order to reduce the manual steps required to run it.

Gradle Wrapper

As developers, we tend to work on multiple projects at the same time, especially when developing on top of a microservice architecture. The manual setup of the tools and their required versions to run these projects can easily become a pain, and that’s no different with Gradle.

Fortunately, we can add Gradle Wrapper to an existing project so we can ship the runnable of Gradle as part of the source code.

How?

It’s as simple as running the wrapper task on the root folder of your project. The following will generate the wrapper of the currently installed version:

gradle wrapper

This will generate the files gradlew and gradlew.bat, and a gradle directory. Now you can simply invoke the Gradle wrapper by running:

./gradlew build

How to specify the Gradle version?

To generate the wrapper of Gradle version 6.0 for example:

gradle wrapper --gradle-version 6.0

Go the Gradle releases page to check what versions are available.

What about old Gradle versions such as 2.3 and older?

First of all, I’d recommend updating to a more up-to-date version unless you have a very good reason to keep it that old. If you have that good reason however, add the following to your build.gradle file:

task wrapper(type: Wrapper) {
   gradleVersion = '2.3'
}

And now you can run:

gradle wrapper

Hope it helps! Cya =]

bgasparotto

Recent Posts

Python function decorator

This guide will show you how to create a Python function decorator with a few…

2 years ago

Got permission denied while trying to connect to the Docker daemon socket

This guide will show you how to fix the error Got permission denied while trying…

2 years ago

Python virtual environment on Intellij IDEA

This guide will show you how to create a Python virtual environment on Intellij IDEA…

2 years ago

Find and kill processes on Linux and Mac by port number

This tutorial will quickly show you how to to find and kill processes on Linux,…

2 years ago

Python: Relocation R_X86_64_PC32 against symbol can not be used when making a shared object Error

This guide shows a possible solution for Python error Relocation R_X86_64_PC32 against symbol can not…

2 years ago

Kubernetes useful commands

I condensed below a cheat sheet of Kubernetes useful commands. I will keep updating this…

2 years ago