4

I have set up a multi-module gradle project with a common module and a ktor module.

The common module is a kotlin multiplatform library.

I would like to be able to serve the javascript files generated from the common library from the ktor server, when I run it from Intellij.

Currently ktor is set up to serve resources as static content:

    static("/static") {
        resources()
    }

The ktor module has a dependency on the common module:

dependencies {
    compile project(':common')
    ...
}

I would assume when running in Intellij to be able to browse to http://localhost:8080/static/common.js to retrieve the outputs of the common module JS build (written to common\build\classes\kotlin\js\main) but this does not work.

1 Answer 1

4

Fixed this by including a copy task. Note that the kotlin full stack mpp here (https://github.com/ktorio/ktor-samples/tree/master/mpp/fullstack-mpp) has an example that uses webpack outputs.

kotlin {
    jvm() {
        task copyJsToJvm(type: Copy) {
            from("$buildDir/classes/kotlin/js/main")
            include '*.*'
            into "$buildDir/classes/kotlin/jvm/main"
        }
        compilations.main {
            tasks.getByName(processResourcesTaskName) {
                dependsOn(copyJsToJvm)
            }
        }
    }
...
}
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.