The docs explain how to make a webpack from kotlin...
# javascript
h
The docs explain how to make a webpack from kotlin/JS, but making a webjar is dfferent (the jar file should contain META-INF and a certain paths like /web/META-INF/resources/webjars/ or so). Is there an easy way to do this? Do we have a gradle plugin to turn to?
c
Hey, this is how I do it. No plugin required since building a webjar is straight forward and just means your sources have to live in a specific path of your jar
Copy code
plugins {
    kotlin("jvm")
    id("com.github.node-gradle.node") version "2.0.0"
}

node {
    version = "12.7.0"
    yarnVersion = "1.17.3"
}

val yarn_bundle by tasks.getting  {
    dependsOn("yarn_install")
}

val build by tasks.getting  {
    dependsOn("yarn_bundle")
}

val jar by tasks.getting(Jar::class)  {
    archiveFileName.set("${project.name}.jar")
    dependsOn("yarn_bundle")
    from(fileTree("dist"))
    into("META-INF/resources")
}
: By referencing the module that has the webjar as artifact it can be loaded into another submodule for examle
Copy code
implementation(project(path = ":frontend", configuration = "default"))
h
Yes, it's just a matter of placing the file inside the correct path in the jar file. Your example is too simple for my needs, though, as I do not use nodeJS: I have a gradle build where I 1) move files from gradle's output structure into the correct webjar path, 2) add javascript files from dependencies to the same folder, 3) apply the Google Closure Compiler to the javascript files, 4) concatenate the resulting files into one, single .js file and remove the others. It's not a very difficult process, but with finding .js files, .meta.js files and .js.map files by iteration over build folder contents, unzipping from dependencies and iterating again to get files from there, concatenating files and deleting unwanted files, I use more than 100 lines in my gradle.build file ... When the jar file is packed and published to our private maven repository, I can then add it as a dependency in our Play! Framework. I'll keep what I have. The only reason I'd prefer to have this as a plugin, is that somebody else would have to maintain the code and update it with new versions of gradle ... :-)