Is there a way to make gradlew available within all sub-directories?


(Phil Swenson) #1

the gradle wrapper is great, except for one thing. If you are in a subdirectory of the project you need to do something like “…/…/gradlew” to run it.

I have the root of the project in my path to avoid this. But we have many projects and they might not be on the same gradle version, so this could be a problem.

So I think this is a unix question actually. Is there a way to make the shell know what directory structure you are in and add the correct gradlew to your path? My guess is the only solution is to write a .rc file and it will change when you “cd” into the root of the project. (I’ve never done this, just guessing). I have no idea how one would do this if you “cd root/subproject/subproject” thought…

thoughts?


(Peter Niederwieser) #2

For *nix there is https://github.com/cbeams/shell-scripts. I highly recommend the “find-gradle” script. I renamed it to “gradlew” and put it on my executable path. Since then I never have to type ‘…/’ again.


(Jörn Huxhorn) #3

That script should totally be added to the gradle distribution. Exactly what I needed!


(nm2501) #4

I haven’t tried the find-gradle script that Peter mentioned because I’m using Windows. However, I solved the same problem using doskey. I added a helper task to a plugin which would generate a batch file for configuring doskey. After invoking the batch file, a gradlew alias would be available from any directory. I only wanted the alias to live as long as the command prompt but it’s possible to make it persistent.


(spencer_allain) #5

This is being tracked also as GRADLE-2429

For convenience, I’ve uploaded the latest versions of those scripts to github:

When I wrote my versions for both unix and windows, I didn’t actually know about find-gradle (as I just found out about it reading this post thread). The main differences between the scripts are that I check the current directory regardless of where it is, and also check in the special “master” directory. That and I do not attempt to run anything but a wrapper script.

-Spencer


(Douglas Borg) #6

I took a slightly different approach with my script. It can be run from any subdirectory and runs the nearest build.gradle file with the nearest gradlew, falling back to system’s gradle if it is not found.

Check out:

https://gist.github.com/4278116

It is based off of the work of Spencer Allain and Chris Beams (mentioned earlier).