phantasmal-world/psoserv/build.gradle.kts

95 lines
2.4 KiB
Plaintext

import org.graalvm.buildtools.gradle.tasks.BuildNativeImageTask
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
id("world.phantasmal.jvm")
kotlin("plugin.serialization")
application
id("org.graalvm.buildtools.native") version "0.9.2"
}
version = "0.0.1"
/** Source code generated by the build script goes here. */
val generatedSrc = layout.buildDirectory.get().asFile.resolve("generated-src/main/kotlin")
kotlin {
sourceSets {
main {
kotlin.setSrcDirs(kotlin.srcDirs + generatedSrc)
}
}
}
val generateVersionInfo by tasks.registering {
group = "code generation"
val packageName = "world.phantasmal.psoserv"
val outputFile = generatedSrc.resolve("${packageName.replace('.', '/')}/VersionInfo.kt")
inputs.property("version", version)
outputs.file(outputFile)
doLast {
outputFile.writeText(
"""
package $packageName
object VersionInfo {
val version: String = "$version"
}
""".trimIndent()
)
}
}
tasks.withType<KotlinCompile>().configureEach {
dependsOn(generateVersionInfo)
}
val mainClassFqn = "world.phantasmal.psoserv.MainKt"
val nativeAgentOutputDir = layout.buildDirectory.get().asFile.resolve("agent-output")
application {
mainClass.set(mainClassFqn)
}
val nativeAgentRun by tasks.registering(JavaExec::class) {
description =
"Run with the GraalVM native-image-agent to produce reflection info etc. for the nativeBuild task."
group = "application"
dependsOn(tasks.build)
outputs.dir(nativeAgentOutputDir)
mainClass.set(mainClassFqn)
classpath = sourceSets.main.get().runtimeClasspath
jvmArgs = listOf("-agentlib:native-image-agent=config-output-dir=$nativeAgentOutputDir")
args = listOf(
"--nostart",
"--config=graalvm-agent.conf",
)
}
nativeBuild {
imageName.set("psoserv")
mainClass.set(mainClassFqn)
buildArgs.addAll(
"--allow-incomplete-classpath",
"-H:ConfigurationFileDirectories=$nativeAgentOutputDir",
)
}
tasks.withType<BuildNativeImageTask>().configureEach {
dependsOn(nativeAgentRun)
inputs.dir(nativeAgentOutputDir)
}
val serializationVersion: String by project.extra
dependencies {
implementation(project(":core"))
implementation(project(":psolib"))
implementation("org.jetbrains.kotlinx:kotlinx-serialization-hocon:$serializationVersion")
}