littlekt-game-template/game/build.gradle.kts

112 lines
4.1 KiB
Text
Raw Normal View History

import org.apache.tools.ant.taskdefs.condition.Os
2022-03-09 16:55:07 -05:00
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)
2022-03-09 16:55:07 -05:00
}
kotlin {
tasks.withType<JavaExec> { jvmArgs("--enable-preview", "--enable-native-access=ALL-UNNAMED") }
2022-03-09 16:55:07 -05:00
jvm {
compilations.all { kotlinOptions.jvmTarget = "21" }
2022-03-09 16:55:07 -05:00
compilations {
val main by getting
val mainClassName = (findProperty("jvm.mainClass") as? String)?.plus("Kt")
if (mainClassName == null) {
project.logger.log(
2022-03-09 16:55:07 -05:00
LogLevel.ERROR,
"Property 'jvm.mainClass' has either changed or has not been set. Check 'gradle.properties' and ensure it is properly set!"
)
}
2022-03-09 16:55:07 -05:00
tasks {
register<Copy>("copyResources") {
group = "package"
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
2024-01-25 11:20:48 -05:00
dependsOn(named("jvmProcessResources"))
2022-03-09 16:55:07 -05:00
from(main.output.resourcesDir)
2024-01-25 11:20:48 -05:00
destinationDir = File("${layout.buildDirectory.asFile.get()}/publish")
2022-03-09 16:55:07 -05:00
}
register<Jar>("packageFatJar") {
group = "package"
archiveClassifier.set("all")
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
dependsOn(named("jvmJar"))
dependsOn(named("copyResources"))
manifest { attributes["Main-Class"] = mainClassName }
2024-01-25 11:20:48 -05:00
destinationDirectory.set(File("${layout.buildDirectory.asFile.get()}/publish/"))
2022-03-09 16:55:07 -05:00
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}"
)
2022-03-09 16:55:07 -05:00
}
}
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"])
)
}
}
}
2022-03-09 16:55:07 -05:00
}
}
}
js {
2022-03-09 16:55:07 -05:00
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")),
)
2022-03-09 16:55:07 -05:00
}
}
this.attributes.attribute(KotlinPlatformType.attribute, KotlinPlatformType.js)
2022-03-09 16:55:07 -05:00
compilations.all { kotlinOptions.sourceMap = true }
}
2022-03-09 16:55:07 -05:00
sourceSets {
val commonMain by getting {
dependencies {
implementation(libs.littlekt.core)
implementation(libs.littlekt.scenegraph)
2022-03-09 16:55:07 -05:00
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
}
2022-08-16 19:44:51 -04:00
}