Hi everyone, not sure if this is the right channel...
# gradle
c
Hi everyone, not sure if this is the right channel for this but maybe someone can send me to the correct channel if I am wrong. I have created a Project with two modules server (ktor jvm) and client (js ir compiler browser target). The goal I am trying to achive is to get both modules to build when ever there is a change that requires that specific module to be rebuild and to load these changes into the runnning application if possible. I therefore activated devmode for ktor and enabled autoreload. I then start the ktor application from within intellij and also run
gradle installDist -t
for the server module in an extra task. Serverreloads work greate with this solution but I can't get the client js part to work propally. For the client part I added the following code to my build.gradle.kts inside my server module
Copy code
tasks.withType<Copy>().named("processResources") {
    dependsOn(":client:browserDistribution")
    from(project(":client").tasks.named("browserDistribution"))
}
The first time I make changes to the client module while
gradle installDist -t
is running the changes get compiled and copied over to the servermodule, but any changes after that don't get copied over, even thougth the build is reran. Am I doing something wrong? Any advice on how to fix this?
v
I have no idea whether it will solve your problem, but your snippet is evil. The
dependsOn
is just senseless if you have the task as input anyway, because then you have an implicit dependency on the task and that is better. But actually referencing tasks from other projects should be avoided as hell. Read here for more information: https://docs.gradle.org/current/userguide/cross_project_publications.html
t
Probably check this sample repo: https://github.com/Kotlin/kotlin-full-stack-application-demo May lead you to the right direction
c
That's what I used as a reference in the first place. But it also uses
tasks.withType<Copy>().named("processResources") {    from(project(":client").tasks.named("browserDistribution"))}
to copy those files over eventhougth it is considered a bad practice according to docs linked above. ^^
v
It's not only bad practice, it only works by accident. You see it often in the wild but that doesn't make it good. That's like building a repackaging fat jar. That's a very common practice out there, but imho a very bad practice and abuse of Java functionality that has way better alternatives and almost only drawbacks.
c
Still the question remains how to do it better then?
v
Like documented on that docu page? Btw. I said up-front that I have no idea whether it is related to your actual problem or whether it will fix it or not. Just that this is bad in the snippet you showed and should probably be changed.