I'm not really a Gradle advanced user, so this may...
# javascript
m
I'm not really a Gradle advanced user, so this may sound kinda dumb, but is it possible to copy the Gradle's
jsBrowserDistribution
output to another project? What I want to do is to copy the output from my
:frontend
module to the resources of my
:backend
(a ktor webserver) module
t
Here you can see example of DCE sync.
In common case:
Copy code
val copyDist by tasks.registering(Copy::class) {
    // task path used
    from(":other-project:super-build-task")

    into("my-dist-folder")
}
h
New Project -> FullStack Application includes this task already
m
Thanks @turansky and @hfhbd, I didn't notice that the Multiplatform task had the "copy files" task, however the multiplatform template project doesn't have multiple modules (only one module, I like keeping my stuff separate in different modules :3) So this is the task that I made:
Copy code
val copyFrontendJavaScript by registering(Copy::class) {
        val jsBrowserProductionWebpack = rootProject.allprojects.first { it.name == "frontend" }.tasks.getByName<org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpack>("jsBrowserProductionWebpack")

        from(File(jsBrowserProductionWebpack.destinationDirectory, jsBrowserProductionWebpack.outputFileName))
        into("build/resources/main/static/v3/assets/js/")
    }
It works, but it isn't as pretty and doesn't have dev mode like @turansky 😛
h
Not tested, but could you use: enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS") in settings.gradle.kts to archive this?
Copy code
val jsBrowserProductionWebpack: org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpack by projects.frontend.tasks
EDIT: looks like it is not possible
t
Copy code
tasks.getByPath(":frontend:jsBrowserProductionWebpack")
?
🚀 1
m
@hfhbd tried that but it doesn't seem to work... well, IDEA doesn't auto complete and I haven't tested by using Gradle directly from the CLI so maybe it is just a IDEA issue However @turansky's version works fine 🙂 Now I'm trying to fix some issues where if it is a clean build, the js file ends up not in the output JAR (probably something related to the task order)
t
Dependency on task required
You can find it my example (first link)
m
I may misunderstanding what your code on the first link does, but I didn't find anywhere there where the code copies the resulting JS files from the
jsBrowserProductionWebpack
task to a folder within the
resources
folder of the JVM JAR (but maybe I'm just being dumb, I don't really know a lot about Gradle :P)
Okay here's a better task that looks better and isn't causing issues when using doing a clean build 🙂
Copy code
val jsBrowserProductionWebpack = tasks.getByPath(":frontend:jsBrowserProductionWebpack") as org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpack

    processResources {
        dependsOn(jsBrowserProductionWebpack)

        from(jsBrowserProductionWebpack.destinationDirectory) {
            into("static/v3/assets/js/")
        }
    }