11import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask
2- import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
32import org.gradle.internal.os.OperatingSystem
43import org.jetbrains.dokka.gradle.DokkaTask
54import org.jetbrains.kotlin.gradle.plugin.KotlinCompilationToRunnableFiles
@@ -30,9 +29,10 @@ val lwjglNatives = when {
3029
3130plugins {
3231 kotlin(" multiplatform" ) version Versions .kotlin
32+ application // to run JVM part
3333 kotlin(" plugin.serialization" ) version Versions .kotlin
3434 id(" org.jetbrains.dokka" ) version Versions .dokka
35- id(" com.github.johnrengelman.shadow" ) version " 5.2.0"
35+ // id("com.github.johnrengelman.shadow") version "5.2.0"
3636 id(" com.github.ben-manes.versions" ) version " 0.29.0"
3737 id(" maven-publish" )
3838 id(" name.remal.check-dependency-updates" ) version " 1.0.211"
@@ -51,9 +51,14 @@ group = "org.baaahs"
5151version = " 0.0.1"
5252
5353kotlin {
54- jvm()
54+ jvm {
55+ withJava()
56+ }
57+
5558 js {
5659 browser {
60+ binaries.executable()
61+
5762 useCommonJs()
5863
5964 webpackTask {
@@ -87,9 +92,11 @@ kotlin {
8792 @Suppress(" UNUSED_VARIABLE" )
8893 val jvmMain by getting {
8994 dependencies {
95+ implementation(" org.jetbrains.kotlinx:kotlinx-html-jvm:${Versions .kotlinxHtml} " )
9096 implementation(" io.ktor:ktor-server-core:${Versions .ktor} " )
9197 implementation(" io.ktor:ktor-server-netty:${Versions .ktor} " )
9298 implementation(" io.ktor:ktor-server-host-common:${Versions .ktor} " )
99+ implementation(" io.ktor:ktor-html-builder:${Versions .ktor} " )
93100 implementation(" io.ktor:ktor-websockets:${Versions .ktor} " )
94101 implementation(" ch.qos.logback:logback-classic:1.2.3" )
95102 implementation(" com.xenomachina:kotlin-argparser:2.0.7" )
@@ -196,16 +203,32 @@ kotlin {
196203 }
197204}
198205
199- // workaround for https://youtrack.jetbrains.com/issue/KT-24463:
200- tasks.named<KotlinCompile >(" compileKotlinJvm" ) {
201- dependsOn(" :copySheepModel" )
202- }
206+ application {
207+ mainClass.set(" baaahs.PinkyMainKt" )
208+
209+ applicationDefaultJvmArgs = listOf (
210+ " -Djava.library.path=${file(" src/jvmMain/jni" )} " ,
211+ " -Dio.ktor.development=true"
212+ )
203213
204- tasks.create<Copy >(" copySheepModel" ) {
205- from(" src/commonMain/resources" )
206- into(" build/classes/kotlin/jvm/main" )
214+ if (isMac()) {
215+ applicationDefaultJvmArgs + = listOf (
216+ " -XstartOnFirstThread" , // required for OpenGL: https://github.com/LWJGL/lwjgl3/issues/311
217+ " -Djava.awt.headless=true" // required for Beat Link; otherwise we get this: https://jogamp.org/bugzilla/show_bug.cgi?id=485
218+ )
219+ }
207220}
208221
222+ // // workaround for https://youtrack.jetbrains.com/issue/KT-24463:
223+ // tasks.named<KotlinCompile>("compileKotlinJvm") {
224+ // dependsOn(":copySheepModel")
225+ // }
226+
227+ // tasks.create<Copy>("copySheepModel") {
228+ // from("src/commonMain/resources")
229+ // into("build/classes/kotlin/jvm/main")
230+ // }
231+
209232tasks.withType(Kotlin2JsCompile ::class ) {
210233 kotlinOptions.sourceMap = true
211234 kotlinOptions.sourceMapEmbedSources = " always"
@@ -221,7 +244,7 @@ tasks.withType(KotlinCompile::class) {
221244}
222245
223246tasks.named<ProcessResources >(" jsProcessResources" ) {
224- dependsOn(" kotlinNpmInstall" ) // for node_modules stuff
247+ // dependsOn("kotlinNpmInstall") // for node_modules stuff
225248
226249 from(" build/js/node_modules/requirejs" ) { include(" require.js" ) }
227250 from(" build/js/node_modules/three/build" ) { include(" three.js" ) }
@@ -245,9 +268,9 @@ tasks.named<ProcessResources>("jsProcessResources") {
245268}
246269
247270tasks.named<ProcessResources >(" jvmProcessResources" ) {
248- dependsOn(" jsBrowserDevelopmentWebpack" )
249-
250- from(" build/distributions" ) { include(" sparklemotion.js" ) }
271+ // dependsOn("jsBrowserDevelopmentWebpack")
272+ //
273+ // from("build/distributions") { include("sparklemotion.js") }
251274
252275 doLast {
253276 createResourceFilesList(File (buildDir, " processedResources/jvm/main" ))
@@ -302,27 +325,43 @@ tasks.create<JavaExec>("runGlslJvmTests") {
302325 }
303326}
304327
305- tasks.create<Copy >(" packageClientResources" ) {
306- dependsOn(" jsProcessResources" , " jsBrowserWebpack" )
307- duplicatesStrategy = DuplicatesStrategy .WARN
308- from(project.file(" build/processedResources/js/main" ))
309- from(project.file(" build/distributions" ))
310- into(" build/classes/kotlin/jvm/main/htdocs" )
328+ // tasks.create<Copy>("packageClientResources") {
329+ // dependsOn("jsProcessResources", "jsBrowserWebpack")
330+ // duplicatesStrategy = DuplicatesStrategy.WARN
331+ // from(project.file("build/processedResources/js/main"))
332+ // from(project.file("build/distributions"))
333+ // into("build/classes/kotlin/jvm/main/htdocs")
334+ // }
335+
336+ // tasks.named<Jar>("jvmJar") {
337+ // dependsOn("packageClientResources")
338+ // duplicatesStrategy = DuplicatesStrategy.WARN
339+ // }
340+
341+ // // include JS artifacts in any JAR we generate
342+ // tasks.getByName<Jar>("jvmJar") {
343+ // val taskName = if (project.hasProperty("isProduction")) {
344+ // "jsBrowserProductionWebpack"
345+ // } else {
346+ // "jsBrowserDevelopmentWebpack"
347+ // }
348+ // val webpackTask = tasks.getByName<KotlinWebpack>(taskName)
349+ // dependsOn(webpackTask) // make sure JS gets compiled first
350+ // from(File(webpackTask.destinationDirectory, webpackTask.outputFileName)) // bring output file along into the JAR
351+ // }
352+
353+ tasks.getByName<JavaExec >(" run" ) {
354+ classpath(tasks.getByName<Jar >(" jvmJar" )) // so that the JS artifacts generated by `jvmJar` can be found and served
311355}
312356
313- tasks.named<Jar >(" jvmJar" ) {
314- dependsOn(" packageClientResources" )
315- duplicatesStrategy = DuplicatesStrategy .WARN
316- }
317-
318- tasks.create<ShadowJar >(" shadowJar" ) {
319- dependsOn(" jvmJar" )
320- from(tasks.named<Jar >(" jvmJar" ).get().archiveFile)
321- configurations = listOf (project.configurations[" jvmRuntimeClasspath" ])
322- manifest {
323- attributes[" Main-Class" ] = " baaahs.PinkyMainKt"
324- }
325- }
357+ // tasks.create<ShadowJar>("shadowJar") {
358+ // dependsOn("jvmJar")
359+ // from(tasks.named<Jar>("jvmJar").get().archiveFile)
360+ // configurations = listOf(project.configurations["jvmRuntimeClasspath"])
361+ // manifest {
362+ // attributes["Main-Class"] = "baaahs.PinkyMainKt"
363+ // }
364+ // }
326365
327366tasks.withType(Test ::class ) {
328367 useJUnitPlatform {
0 commit comments