gdub (gw
on the command line) is a gradle
/ gradlew
wrapper. Not to beconfused with the Gradle Wrapper, gw
invokes ./gradlew
onprojects where one is configured, and falls back to use the gradle
from the$PATH
if a wrapper is not available. Also, gw
is 66% shorter to type than gradle
and 78% shorter to type than ./gradlew
.
There are now a few ways to install gdub, with more on the way. Use whichever ismost convenient for you or feel free to suggest another!
If you are on OSX and not using homebrew, I'm not quite sure what to do withyou. Install gdub with homebrew like so:
brew install gdub
If you use MacPorts, you can install gdub like so:
sudo port install gdub
If you use bpkg, you may install like so:
bpkg install dougborg/gdub -g
You will probably want to install Gradle first. While this is nottechnically necessary if all your projects are using a Gradle Wrapper, it is agood idea to have the latest version of gradle
available system-wide becausesome handy Gradle features are available outside the context of an existingproject.
Check out a copy of the gdub repository. Then, either add the gdub bin
directory to your $PATH
, or run the provided install
command with thelocation to the prefix in which you want to install gdub. The default prefix is/usr/local
.
For example, to install gdub into /usr/local/bin
:
git clone https://github.com/dougborg/gdub.git
cd gdub
./install
Note: you may need to run ./install
with sudo
if you do not havepermission to write to the installation prefix.
gradle
commandFor maximum fidelity add a gradle
alias to gw
to your shell's configurationfile.
Example bash:
echo "alias gradle=gw" >> ~/.bashrc
source ~/.bashrc
From now on you can just type gradle ...
from wherever you are and gw
takescare of the rest. Happiness ensues!
gradle
and gradlew
gdub is a convenience for developers running local Gradle commands and addressesa few minor shortcomings of gradle
and gradlew
's commandline behaviour.These are known issues, and they are set to be addressed in future versions ofGradle. If you are interested in the discussions surrounding them, check out:
Here are the issues I feel are most important, and the ones gdub attempts toaddress:
build.Gradle
If you are using the gradle
command, and you are not in the same directory asthe build.gradle
file you want to run, you have to provide gradle
the path.Depending on where you happen to be, this can be somewhat cumbersome:
$ pwd
~/myProject/src/main/java/org/project
$ gradle -b ../../../../../build.gradle build
With gw
, this becomes:
$ gw build
gradlew
If you are using gradlew
and you want to run your build, you need to dosomething similiar and provide the relative path to the gradlew
script:
$ pwd
~/myProject/src/main/java/org/project/stuff
$ ../../../../../../gradlew build
Again, with gw
this becomes:
$ gw build
I don't even want to type out an example of this, let alone do it on aday-to-day basis. Use your imagination.
./gradlew
to run the Gradle wrapper is kind of inconvenientEven with tab completion and sitting at the root of your project, you have totype at least ./gr<tab>
. It gets a bit worse if you happen to have aGradle.properties
file, and with the Gradle wrapper, you have a gradle
directory to contend with as well. A simple alias would solve this problem, butyou still have the other (more annoying) issues to contend with.
gradlew
, but typed gradle
insteadThis can be a problem if the project you are building has customizations to theGradle wrapper or for some reason is only compatible with a certain version ofGradle that is configured in the wrapper. If you know the project uses Gradle,you may be tempted to just use your own system's Gradle binary. This might beok, or it might cause the build to break, but if a project has a gradlew
, itis a pretty safe bet you should use it, and not whatever Gradle distribution youhappen to have installed on your system.
gw
payoffAnywhere you happen to be on your project, you can run the Gradle tasks of yourproject by typing gw <tasks>
, regardless of whether you use the Gradle Wrapperin your project or not.
gw
works by looking upwards from your current directory and will run thenearest build.Gradle
file with the nearest gradlew
. If a gradlew
cannotbe found, it will run the nearest build.Gradle
with your system's Gradle. Thisis probably always what you want to do if you are running Gradle from within aproject's tree that uses the Gradle build system.