Gradle howto

We treat gradle as a build tool and dependency management system. We use it to (a) automagically manage the libraries our project uses, and (b) compile and run our code by typing short commands.

Checking your installation

To check whether your machine already has gradle installed or not, type

$ gradle -v

If gradle is already installed, you’ll be told the gradle version, build time, revision, and other related information.

If gradle is not installed, you’ll be told that the gradle command cannot be found.

First make sure your computer has Java JDK 8 and gradle installed! If using a Mac, follow the osx-software-install-how-to instruction. If using Ubuntu, follow the ubuntu-software-install-how-to instruction.

Compiling programs with gradle

To compile your kotlin program, first make sure your shell’s current directory is in the root directory of your gradle project. For example, if your project is at ~/mcs178/nbody then you should type

$ cd ~/mcs178/nbody

To actually tell gradle to go ahead and compile, type

$ gradle compileKotlin

Running programs with gradle

Make sure your shell’s current directory is the root directory of your gradle project. Change directory into it if necessary.

To run your Kotlin program with no command line arguments, type

$ gradle run

To run your Kotlin program and give it command line arguments, say, “x y z”, type

$ gradle run --args="x y z"

The string following --args= needs be quoted only if it has whitespaces in it.

Digging deeper

There are many more tasks the gradle command can do. To see what tasks are available, type

$ gradle tasks

while your current working directory is the root directory of a gradle project.

To learn more about gradle, consult the official gradle documentation at https://docs.gradle.org/current/userguide/userguide.html