Gradle Setup
This guide will walk you through the way we recommend setting up Gradle for your games. This is also how we created our Games repository internally.
Version Catalogs
If you use subprojects (mentioned later in this guide), we recommend setting up a Gradle version catalog. This allows you to share dependency versions between multiple subprojects, and Minestom uses it internally.
To set up a version catalog, follow this guide from the Gradle documentation.
Subprojects
If you plan on making multiple games for your server (even a lobby and one minigame), we recommend placing them all in one project so that they can share common code.
You should create a common
Gradle subproject which your games can depend on. In that project,
you can write utilities, like methods that create packets or format chat messages.
You can also place common game modules in the common
subproject. That way, all of your games can
import and use
them.
Learn more about Gradle subprojects here.
Setting up subprojects
-
Create a folder in the root of your project. Name it according to the name of your minigame.
-
Inside that folder, create two files:
build.gradle.kts
andsettings.gradle.kts
. These define the build configuration for the subproject. -
In
build.gradle.kts
, configure your subproject to build its own JAR. For example: -
Configure your Gradle build settings.
-
Include your subproject in your main project’s build step. To do this, add the following to your root project’s
settings.gradle.kts
: -
Create the source files for your project. In your subproject folder you created in Step 1, create the following directory structure:
-
Open up the
game.properties
file and add this to it: -
In your
src
folder, create the package and main class you defined in Step 7. Make sure it extends thecom.bluedragonmc.server.Game
class. -
Follow the Creating a Game guide to start building your first game!
When you run a Gradle build on your root project, the subproject’s JARs will be placed in build/libs
inside your subproject’s directory.
If you want them to be automatically copied to the root project or want a Gradle task to run a development server, see the Gradle run task guide.