martmists

    martmists

    1 year ago
    Copying from #javascript: • Just started a kotlin-mpp full-stack project from IDEA; What gradle task do I run to make it build the entire project as one jar, and where should I put the assets and such? • Also, is there a way to use sass/less easily with the standard setup or no? •
    Execution failed for task ':jvmProcessResources'.
    > Entry server_style.css is a duplicate but no duplicate handling strategy has been set. Please refer to <https://docs.gradle.org/7.1/dsl/org.gradle.api.tasks.Copy.html#org.gradle.api.tasks.Copy:duplicatesStrategy> for details.
    I also get this while trying to run my project, it says server_style.css is duplicate but it's only in jvmMain/resources and not in jsMain/resources or commonMain/resources
    Tomasz Krakowiak

    Tomasz Krakowiak

    1 year ago
    I also get this while trying to run my project, it says server_style.css is duplicate but it's only in jvmMain/resources and not in jsMain/resources or commonMain/resources
    Maybe it's this one - https://youtrack.jetbrains.com/issue/KT-46165 What version of kotlin plugin are you using?
    For packaging compiled js, I use something like that:
    tasks.getByName<Jar>("jvmJar") {
        dependsOn(tasks.getByName("jsBrowserProductionWebpack"))
        val jsBrowserProductionWebpack = tasks.getByName<KotlinWebpack>("jsBrowserProductionWebpack")
        into("static") {
            from(File(jsBrowserProductionWebpack.destinationDirectory, jsBrowserProductionWebpack.outputFileName))
            from(File(jsBrowserProductionWebpack.destinationDirectory, jsBrowserProductionWebpack.outputFileName + ".map"))
        }
    }
    Not sure if there's a better option.
    To package everything into single jar with dependencies, I use separate plugin. There are multiple choices. Personally I use spring-boot plugin, but I am writing spring boot applications.
    I recommend this tutorial from kotlin hands-on - https://play.kotlinlang.org/hands-on/Full%20Stack%20Web%20App%20with%20Kotlin%20Multiplatform/04_Frontend_Setup They package js in similar way to mine.
    Here's my sample project with packaging js resources into jar - https://github.com/carrat-framework/carrat-demo-tictactoe/blob/master/build.gradle.kts It handles both packaging js resources to "static" directory in jar and exposing them to webpack for
    browser*Run
    tasks.
    I think you should be able to compile sass/less both using gradle plugin or webpack plugin, but personally I have no experience with it. You may have more luck getting replies by posting problems/questions separately.
    martmists

    martmists

    1 year ago
    Using the same setup from the hands-on guide results in project-1.0-SNAPSHOT.jar being empty (aside from manifest), project-js-1.0-SNAPSHOT containing a lot of JS files rather than a single one (as well as the client_style.css which is good) and the project-jvm-1.0-SNAPSHOT jar has the expected resources from the server, but also has the assets in the root, as well as an empty zip and tar (like the first jar). It also seems to be missing the main-class property in the manifest, so you can't even run it 😕