mirror of
https://github.com/littlektframework/littlekt-game-template.git
synced 2025-01-10 11:30:53 -07:00
gradle: add workaround for running jvm on mac with -XstartOnFirstThread (#4)
This commit is contained in:
parent
1eafaff2cf
commit
4e45601683
1 changed files with 23 additions and 5 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
import org.apache.tools.ant.taskdefs.condition.Os
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinJsCompilerType
|
import org.jetbrains.kotlin.gradle.plugin.KotlinJsCompilerType
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
|
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
|
||||||
|
|
||||||
|
@ -17,17 +18,19 @@ kotlin {
|
||||||
compilations {
|
compilations {
|
||||||
val main by getting
|
val main by getting
|
||||||
|
|
||||||
val mainClass = (findProperty("jvm.mainClass") as? String)?.plus("Kt")
|
val mainClassName = (findProperty("jvm.mainClass") as? String)?.plus("Kt")
|
||||||
?: project.logger.log(
|
if (mainClassName == null) {
|
||||||
|
project.logger.log(
|
||||||
LogLevel.ERROR,
|
LogLevel.ERROR,
|
||||||
"Property 'jvm.mainClass' has either changed or has not been set. Check 'gradle.properties' and ensure it is properly set!"
|
"Property 'jvm.mainClass' has either changed or has not been set. Check 'gradle.properties' and ensure it is properly set!"
|
||||||
)
|
)
|
||||||
|
}
|
||||||
tasks {
|
tasks {
|
||||||
register<Copy>("copyResources") {
|
register<Copy>("copyResources") {
|
||||||
group = "package"
|
group = "package"
|
||||||
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
||||||
from(main.output.resourcesDir)
|
from(main.output.resourcesDir)
|
||||||
destinationDir = File("$buildDir/publish")
|
destinationDir = File("${layout.buildDirectory}/publish")
|
||||||
}
|
}
|
||||||
register<Jar>("packageFatJar") {
|
register<Jar>("packageFatJar") {
|
||||||
group = "package"
|
group = "package"
|
||||||
|
@ -36,9 +39,9 @@ kotlin {
|
||||||
dependsOn(named("jvmJar"))
|
dependsOn(named("jvmJar"))
|
||||||
dependsOn(named("copyResources"))
|
dependsOn(named("copyResources"))
|
||||||
manifest {
|
manifest {
|
||||||
attributes["Main-Class"] = mainClass
|
attributes["Main-Class"] = mainClassName
|
||||||
}
|
}
|
||||||
destinationDirectory.set(File("$buildDir/publish/"))
|
destinationDirectory.set(File("${layout.buildDirectory}/publish/"))
|
||||||
from(
|
from(
|
||||||
main.runtimeDependencyFiles.map { if (it.isDirectory) it else zipTree(it) },
|
main.runtimeDependencyFiles.map { if (it.isDirectory) it else zipTree(it) },
|
||||||
main.output.classesDirs
|
main.output.classesDirs
|
||||||
|
@ -47,6 +50,21 @@ kotlin {
|
||||||
project.logger.lifecycle("[LittleKt] The packaged jar is available at: ${outputs.files.first().parent}")
|
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 {
|
compilations.all {
|
||||||
|
|
Loading…
Reference in a new issue