Hello! I have been unable to find documentation on...
# multiplatform
a
Hello! I have been unable to find documentation on how to accomplish a certain goal with gradle in a multiplatform project. My personal website is written front/back in Kotlin. There is a tiny amount of frontend code that I compile to JS, and the rest is generated by the Kotlin/JVM backend. I have had a solution to compile the frontend code into JS, then bake the JS into my JAR so I can serve it. While attempting to upgrade to the latest version of everything today, discovered my old way of doing it is now deprecated:
Copy code
application { mainClass.set("sh.adamcooper.MainKt") }

tasks.named<Copy>("javaProcessResources") {
    val jsBrowserDistribution = tasks.named("jsBrowserDistribution")
    from(jsBrowserDistribution)
}

tasks.named<Jar>("javaJar") {
    duplicatesStrategy = DuplicatesStrategy.INCLUDE
    manifest { attributes["Main-Class"] = application.mainClass }
    from(configurations.runtimeClasspath.get().map { if (it.isDirectory) it else zipTree(it) })
    with(tasks.jar.get() as CopySpec)
}

tasks.named<JavaExec>("run") {
    dependsOn(tasks.named<Jar>("javaJar"))
    classpath(tasks.named<Jar>("javaJar"))
}
Is there a supported/canonical way to accomplish this now?
e
I think that has never been the right way to do it
you could try
Copy code
kotlin {
  sourceSets {
    jvmMain {
      resources.srcDir(tasks.named("jsBrowserDistribution"))
a
Thanks for your reply! Unfortunately, this didn't work. EDIT: The code I posted actually does not work
t
What @ephemient has proposed is the correct way to do it. What is not working for you with this approach?
a
@tapchicoma Sorry for lack of detail. It appears this overwrites other resources I serve, including CSS (which is weird, because I generate it with kotlin-css. I tried using this instead with the same result:
Copy code
resources.setSrcDirs(listOf("src/jvm/main/resources", tasks.named("jsBrowserDistribution")))
The path is correct; I organize my repo a little differently. Previously, that path was the only resource dir I set and it worked fine
🤔 1