Skip to content

Commit 2a9f2f4

Browse files
committed
Changed build.gradle to create a script (build/run) to run the server
1 parent c4b03de commit 2a9f2f4

2 files changed

Lines changed: 41 additions & 1 deletion

File tree

build.gradle.kts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,16 @@ application {
5959
}
6060

6161
sourceSets {
62+
main {
63+
java {
64+
output.setResourcesDir(destinationDirectory.get())
65+
}
66+
}
6267
create("utility")
6368
}
6469

70+
tasks.named("processResources").configure { dependsOn("compileJava") }
71+
6572
val utilityImplementation by configurations.getting {
6673
extendsFrom(configurations.implementation.get())
6774
}
@@ -161,3 +168,36 @@ tasks.withType<Test>().configureEach {
161168
exceptionFormat = TestExceptionFormat.FULL
162169
}
163170
}
171+
172+
tasks.named("classes") {
173+
dependsOn("createRunScript")
174+
}
175+
176+
tasks.register("createRunScript") {
177+
dependsOn("compileJava", "compileKotlin", "processResources")
178+
179+
doLast {
180+
// Get the Java executable from JAVA_HOME environment variable
181+
val javaHome = System.getenv("JAVA_HOME") ?: throw IllegalStateException("JAVA_HOME is not set")
182+
val javaExecutable = "$javaHome/bin/java"
183+
184+
// Collect runtime classpath elements into a single string with path separator
185+
val runtimeClasspath = configurations["runtimeClasspath"].files.joinToString(File.pathSeparator) {
186+
it.absolutePath
187+
}
188+
189+
// Get the output directory for the main/java source set
190+
val mainJavaOutputDir = project.sourceSets["main"].java.destinationDirectory.get().asFile.absolutePath
191+
192+
// Assemble the module-path to include both the runtime classpath and the main/java output directory
193+
val modulePath = "$runtimeClasspath${File.pathSeparator}$mainJavaOutputDir"
194+
195+
// Assemble the command
196+
val command = "clear; $javaExecutable -ea -p $modulePath -m holocore/com.projectswg.holocore.ProjectSWG --print-colors"
197+
198+
// File to write the run command
199+
val outputFile = file("${layout.buildDirectory.asFile.get().absolutePath}/run")
200+
outputFile.writeText(command)
201+
outputFile.setExecutable(true)
202+
}
203+
}

pswgcommon

0 commit comments

Comments
 (0)