littlekt-game-template/game/build.gradle.kts
2024-01-25 11:20:48 -05:00

141 lines
4.7 KiB
Text

import org.apache.tools.ant.taskdefs.condition.Os
import org.jetbrains.kotlin.gradle.plugin.KotlinJsCompilerType
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
repositories {
mavenCentral()
maven(url = "https://maven.pkg.jetbrains.space/public/p/kotlinx-html/maven")
}
plugins {
kotlin("multiplatform")
id("com.android.application")
}
kotlin {
androidTarget()
jvm {
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 {
project.logger.lifecycle("[LittleKt] The packaged jar is available at: ${outputs.files.first().parent}")
}
}
// workaround for https://youtrack.jetbrains.com/issue/KT-62214
if (Os.isFamily(Os.FAMILY_MAC) && mainClassName != null) {
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"])
)
}
}
}
}
}
compilations.all {
kotlinOptions.jvmTarget = "11"
}
testRuns["test"].executionTask.configure {
useJUnit()
}
}
js(KotlinJsCompilerType.IR) {
binaries.executable()
browser {
testTask {
useKarma {
useChromeHeadless()
}
}
}
this.attributes.attribute(
KotlinPlatformType.attribute,
KotlinPlatformType.js
)
compilations.all {
kotlinOptions.sourceMap = true
}
}
sourceSets {
val commonMain by getting {
dependencies {
implementation(libs.littlekt.core)
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
val androidMain by getting
}
}
android {
sourceSets["main"].apply {
manifest.srcFile("src/androidMain/AndroidManifest.xml")
assets.srcDirs("src/commonMain/resources")
}
compileSdk = (findProperty("android.compileSdk") as String).toInt()
defaultConfig {
minSdk = (findProperty("android.minSdk") as String).toInt()
targetSdk = (findProperty("android.targetSdk") as String).toInt()
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
}
rootProject.extensions.configure<org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension> {
versions.webpackCli.version = "4.10.0"
}