How to run Gradle wrapper from any subdir with Gdub


Gradle is a popular and flexible build system for JVM-based languages. We use Gradle as the build system for Mesos Elasticsearch. In this blog I discuss two Gradle concepts: the Gradle wrapper and Gdub, a tool that allows you to run the Gradle wrapper from any subdirectory.

gradlew – The Gradle wrapper

The Gradle wrapper, gradlew, is a shell script that downloads a specific Gradle distribution. This way a software project can configure a version of Gradle and everyone who runs gradlew will use the version specified in the project. This makes for a portable build. To try it out clone Mesos Elasticsearch and run

frank@franktop:~/src/mesos-elasticsearch$ ./gradlew clean build
Picked up JAVA_TOOL_OPTIONS: -javaagent:/usr/share/java/jayatanaag.jar

Now gradlew will fetch gradle version 2.3 and install it under ~/.gradle/wrapper/dists and use that version from then on. Neat! The Gradle wrapper scripts and config can be generated by adding a wrapper task in your build.gradle file. For more information on how to do this see the Official Gradle wrapper documentation.

gdub – A Gradle / gradlew wrapper

If you have used gradlew for a while you probably recognize the following scenario. You want to run gradlew from a subdirectory. This subdirectory could be several levels deep so you have to invoke gradlew like this: ../../../gradlew. It may not sound like a problem but when you use your build system intensively it can become quite annoying. Luckily there is a simple solution…gdub! Gdub locates the gradle wrapper in an ancestor directory. Exactly what we want! Install gdub like this:

git clone
cd gdub

and run gw plus any gradle tasks and off you go!

frank@franktop:~/src/mesos-elasticsearch/scheduler$ gw clean build
Using gradle at '/home/frank/src/mesos-elasticsearch/gradlew' to run buildfile '/home/frank/src/mesos-elasticsearch/scheduler/build.gradle':

For more information on Gdub checkout the Gdub Github page

The following two tabs change content below.

Frank Scholten

Senior Software Engineer at Container Solutions
Frank is a senior software engineer at Container Solutions. He is enthusiastic about Open Source software development, process improvement and automation in particular. Drawing on experience from a wide range of projects he is always on the lookout for new technologies, methods and ways to improve things and likes to write on speak on these topics.

Leave a Reply

Your email address will not be published. Required fields are marked *