Gradle Run Task
BlueDragon projects currently have a lot of moving parts. You can automate most of the repetitive file copying with Gradle tasks. This guide provides a few examples to help you get a development environment up and running quickly.
Copy JARs to a central location
Here is an example of a Gradle task that will copy your subprojects’ JARs after building. Use this in conjunction with the Subprojects section of the Gradle Setup guide.
// Copy all built game JARs to the root build foldertasks.register("copyJars", Copy::class) { subprojects.forEach { subproject -> if (subproject.name == "testing" || subproject.name == "common") return@forEach // Exclude the `testing` and `common` projects dependsOn(subproject.tasks.build) // Ensure this task runs after the subproject builds from(subproject.buildDir.path + "/libs/" + subproject.name + "-1.0-SNAPSHOT.jar") } into("${buildDir}/all-jars")}
// After the whole project is built, run the task we just created to copy the JARstasks.build.configure { finalizedBy(tasks["copyJars"])}Runnning a development server
The easiest way to run a dev server is using a Gradle task to copy the JARs and start the server for you.
Developing the Server project
After adding the copyJars task from the prior section, add the following tasks to your Gradle build script.
This assumes you have cloned the BlueDragonMC/Server project in a sibling directory to your games Gradle project.
// For development: copy build game JARs into the `run` foldertasks.register("copyDev", Copy::class) { dependsOn("copyJars") from("${buildDir}/all-jars") into("${projectDir}/run/games/")}
// For development: build the sibling `Server` projecttasks.register("buildServerDev", Exec::class) { workingDir = File(projectDir.parent, "Server") commandLine = listOf("../Server/gradlew", "build", "-x", "test")}
// For development: copy the `Server` project artifact to the `run` foldertasks.register("copyServerDev", Copy::class) { dependsOn("buildServerDev") from("${projectDir}/../Server/build/libs/Server-1.0-SNAPSHOT-all.jar") into("${projectDir}/run") rename { "server.jar" }}
tasks.register("cleanRunFolder", Delete::class) { delete("${projectDir}/run/games", "${projectDir}/run/server.jar")}
tasks.clean.configure { dependsOn(tasks["cleanRunFolder"])}
// For development: uses the outputs of the above tasks to start a dev servertasks.register("runDev", Exec::class) { dependsOn(tasks["copyServerDev"]) dependsOn(tasks["copyDev"]) workingDir = File(projectDir, "run") commandLine = listOf("java", "-jar", "${projectDir}/run/server.jar")}Then, whenever you want to start a dev server, you can run gradle runDev or add it as an IntelliJ run configuration.
Using the prebuilt Server project
If you want to use the prebuilt Server project instead of cloning it locally, take the code from the last section and make the following modifications:
- Delete the
buildServerDevandcopyServerDevtask definitions - Remove the
dependsOncall forcopyServerDevin therunDevtask definition. - In the
cleanRunFoldertask definition, remove"${projectDir}/run/server.jar"from thedeletecall. - Copy a compiled BlueDragonMC/Server JAR into the
rundirectory in your project. Rename it toserver.jar. - You can now run
gradle runDevto start a dev server using a precompiled BlueDragonMC/Server JAR!
Runtime requirements
When you run the development server, you will need to start up two external services:
- MongoDB for storing player data and permissions
- LuckPerms for querying and updating player permissions
The easiest way to do this is with Docker. Follow this guide to start them up, and make sure they are running when you use the runDev Gradle task. If not, the development server will fail to start.
If you do not have any permissions, follow this guide to give them to yourself.