Maybe the way webjars packages their stuff?
# javascript
s
Maybe the way webjars packages their stuff?
z
I was able to do so by adding a task to create a webjar when using the kotlin-frontend plugin it looked kind of like:
Copy code
task webJar(type: Jar, dependsOn: 'build') {
  from fileTree('build/bundle')
  into "META-INF/resources"
}
s
@Zachary Grafton Thanks! I'm using the newest kotlin MPP plugin with the js target, since the kotlin frontend plugin is deprecated (I think). But something similar should work.
z
I had to spend some time tinkering with some configurations and artifacts to get it to work in a multi module gradle project though and I ran into a bug in
kotlin-frontend
project that stopped me from combining it with a MPP project
s
The multiplatform plugin adds a JsJar task, which should be configurable I think. The issue is that it somehow runs webpack too. TBH the MPP stuff still seems very experimental and largely undocumented.
z
A lot of the JS stuff seems experimental. I had to tinker for a couple of hours to get the kotlin js react project I created to generate a jar that I could depend on in a spring boot project to work
s
Yeah, in my use case it's particularly useful though. In my situation I have a JVM main that runs ktor (along with other client side stuff, its a plugin for an existing application) and I want it to serve the JS from a sibling JS target. Because Ktor already has webjar support I thought it'd be convenient to package the JS target as a webjar. Then you can just use the JsJar task output as a dependency to the jvm runtimeOnly configuration:
Copy code
runtimeOnly(tasks["jsJar"].outputs.files)
That should actually chain the task dependencies correctly too which is nice.
Looks like JsJar doesn't generate a webpacked jar. Seems like this will require a custom jar task
z
Mine was a similar set up, JVM main spring boot application and a JS react project. I needed it to be in a webjar, but couldn't find an option. I had to add the above task and it wouldn't work even after that as the project nature was JS on the output and the JVM project wouldn't pick up the dependency because of that. So, I had to add a webjar configuration and an artifact to get it to work correctly.
s
@Zachary Grafton There is a webpack task which builds a dependency-free bundle. I also configured a new jar task to build the webjar: https://kotlinlang.slack.com/archives/C3PQML5NU/p1567695670142100?thread_ts=1567540262.137200&cid=C3PQML5NU