-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
73 lines (61 loc) · 2.06 KB
/
build.gradle.kts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
plugins {
kotlin("jvm") version "2.0.0"
}
group = "com.bluedragonmc"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
}
dependencies {
testImplementation(kotlin("test"))
}
tasks.test {
useJUnitPlatform()
}
kotlin {
jvmToolchain(21)
}
// Copy all built game JARs to the root build folder
tasks.register("copyJars", Copy::class) {
subprojects.forEach { subproject ->
if (subproject.name == "common") return@forEach // Exclude the `common` project because it's a library, not a game
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 JARs
tasks.build.configure {
finalizedBy(tasks["copyJars"])
}
// For development: copy build game JARs into the `run` folder
tasks.register("copyDev", Copy::class) {
dependsOn("copyJars")
from("${buildDir}/all-jars")
into("${projectDir}/run/games/")
}
// For development: build the sibling `Server` project
tasks.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` folder
tasks.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 server
tasks.register("runDev", Exec::class) {
dependsOn(tasks["copyServerDev"])
dependsOn(tasks["copyDev"])
workingDir = File(projectDir, "run")
commandLine = listOf("java", "-jar", "${projectDir}/run/server.jar")
}