Text Adventure Time! (Building the Game with Gradle)

Some time ago, when I was brushing off my Java, I wanted to get my hands dirty while making something fun. I LOVE text adventure RPGs, so that’s what I attempted to build.

This is the sixth post documenting my single user dungeon development adventure.

In our last Java Text Aventure post, we left off at commit 522e275, where we added object loading from files.

In this post I’ll be covering the addition of a Gradle build.

Here is the list of posts published on this project so far!

Check out the tag for this post and follow along!


Target tagged commit:

Setting up the Gradle build

A simple build.gradle file is added to the root of the project

First, we tell Gradle that our project is a Java project with the line apply plugin: 'java'. This handles the compiler setup; Gradle looks in the $PATH and $JAVA_HOME vars for the Java binaries. This can also be overridden using a gradle.properties file at the root, and referencing your Java install directory like so:

For some reason I thought I had to have this gradle.properties file, which tightly coupled the configuration to my particular install directory. You’ll need to remove this file to enable Gradle to find your Java binaries.

Next, we tell Gradle how to build our jar and give it parameters for the manifest. We define the Main-Class attribute, and point it to the class file containing our main method. The Application.java class contains this method, and lives in the directory src/java/main/com/kosn/application/. Notice how src/java/main are excluded from the Main-Class attribute, and the ‘/‘ have been replaced with ‘.‘.

Building the Gradle wrapper

The above works just fine, and the game can be built using the command gradle clean build, but only if you have the Gradle program installed. Fortunately, Gradle gives us the option to create a sharable wrapper which, when invoked, downloads the requisite Gradle release to a temp directory and uses that to build the project. This means the target machine does not have to have Gradle installed to build the project. Neat!

To create the wrapper, I used this command:

This added wrapper files at gradle/wrapper/, a shell script gradlew, and a batch file gradlew.bat at the root. Now we can build the game without installing Gradle with ./gradlew clean build.

Test the build and run the game

Running the game:


Matthew Odle

Indie dev, autodidactic polyglot, lover of programming, dad, musician, writer, mentor

2 thoughts on “Text Adventure Time! (Building the Game with Gradle)

Join the Discussion