2

In Kotlin 1.2.61 it was possible to have a Gradle dependency from a kotlin-jvm module to a kotlin-js module.

This is useful for including the generated js files in a self-contained jar to serve them as static resources.

However, as of Kotlin 1.2.70 there is a restriction that prevents adding a dependency from a kotlin-jvm module to a kotlin-js module, see: issue.

What is the supported way to make sure that a kotlin-js module gets built before the a kotlin-jvm module, so that the kotlin-js dist files can be included in the kotlin-jvm module (presumably without adding a dependency between them)?

1 Answer 1

1

Answering own question, turns out that the Kotlin frontend plugin is deprecated, and the supported solution is to use the Multiplatform plugin.

I was able to get it working with Kotlin Gradle DSL, with a Spring Boot back-end (including being able to debug from IDE) and hot-reload of React front-end: https://github.com/alexoooo/sample-multiplatform-boot-react

The proj-jvm build.gradle.kts declares a dependency on the proj-js module:

tasks.withType<ProcessResources> {
    val jsProject = project(":proj-js")
    val task = jsProject.tasks.getByName("browserProductionWebpack") as KotlinWebpack

    from(task.destinationDirectory!!) {
        into("public")
    }

    dependsOn(task)
}

Note that Kotlin multiplatform projects are currently experimental, and some of the details are likely to change as the new IR is introduced: https://blog.jetbrains.com/kotlin/2020/03/kotlin-1-4-m1-released/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.