littlekt-game-template/game/build.gradle.kts
Colt Daily fc0503d099
Update template to work with LittleKt 0.10.0 WebGPU update (#6)
* update template to work with new WebGPU LittleKt 0.10.0 update

* remove SNAPSHOT version of LittleKt

* gradle: update to 8.5
2024-07-16 10:27:33 -04:00

111 lines
4.1 KiB
Text

import org.apache.tools.ant.taskdefs.condition.Os
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
repositories {
maven(url = "https://maven.pkg.jetbrains.space/public/p/kotlinx-html/maven")
}
plugins {
alias(libs.plugins.kotlin.multiplatform)
}
kotlin {
tasks.withType<JavaExec> { jvmArgs("--enable-preview", "--enable-native-access=ALL-UNNAMED") }
jvm {
compilations.all { kotlinOptions.jvmTarget = "21" }
compilations {
val main by getting
val mainClassName = (findProperty("jvm.mainClass") as? String)?.plus("Kt")
if (mainClassName == null) {
project.logger.log(
LogLevel.ERROR,
"Property 'jvm.mainClass' has either changed or has not been set. Check 'gradle.properties' and ensure it is properly set!"
)
}
tasks {
register<Copy>("copyResources") {
group = "package"
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
dependsOn(named("jvmProcessResources"))
from(main.output.resourcesDir)
destinationDir = File("${layout.buildDirectory.asFile.get()}/publish")
}
register<Jar>("packageFatJar") {
group = "package"
archiveClassifier.set("all")
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
dependsOn(named("jvmJar"))
dependsOn(named("copyResources"))
manifest { attributes["Main-Class"] = mainClassName }
destinationDirectory.set(File("${layout.buildDirectory.asFile.get()}/publish/"))
from(
main.runtimeDependencyFiles.map { if (it.isDirectory) it else zipTree(it) },
main.output.classesDirs
)
doLast {
logger.lifecycle(
"[LittleKt] The packaged jar is available at: ${outputs.files.first().parent}"
)
}
}
if (Os.isFamily(Os.FAMILY_MAC)) {
register<JavaExec>("jvmRun") {
jvmArgs("-XstartOnFirstThread")
mainClass.set(mainClassName)
kotlin {
val mainCompile = targets["jvm"].compilations["main"]
dependsOn(mainCompile.compileAllTaskName)
classpath(
{ mainCompile.output.allOutputs.files },
(configurations["jvmRuntimeClasspath"])
)
}
}
}
}
}
}
js {
binaries.executable()
browser {
testTask { useKarma { useChromeHeadless() } }
commonWebpackConfig {
devServer =
(devServer
?: org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig
.DevServer())
.copy(
open = mapOf("app" to mapOf("name" to "chrome")),
)
}
}
this.attributes.attribute(KotlinPlatformType.attribute, KotlinPlatformType.js)
compilations.all { kotlinOptions.sourceMap = true }
}
sourceSets {
val commonMain by getting {
dependencies {
implementation(libs.littlekt.core)
implementation(libs.littlekt.scenegraph)
implementation(libs.kotlinx.coroutines.core)
}
}
val commonTest by getting {
dependencies {
implementation(kotlin("test"))
}
}
val jvmMain by getting
val jvmTest by getting
val jsMain by getting {
dependencies {
implementation(libs.kotlinx.html.js)
}
}
val jsTest by getting
}
}