Not sure if I missed out something, does the JVM t...
# gradle
j
Not sure if I missed out something, does the JVM target “application” plugin able to create fat jar for deployment? Can not locate one, have to use another plugin like shadow. I’m new to JVM world, isn’t fat jar the preferable way of distributing JVM app? Why not support fat jar directly in “application” plugin?
s
Are you using a multiplatform project?
j
No. IntelliJ new project > Gradle > Kotlin/JVM. And then manually add the “application” into plugins section of build.gradle file. I tried to use main.kts to create a simple command line script but failed, so I’m creating a JVM app instead. So now want to deploy the app. I can see the build gradle task to create distribution but its creating a batch script and house all dependencies jar in a jar sub folder. Its cleaner to have just one fat jar file for deployment. Can’t really use native as the app is doing web scraping using jsoup, and I don’t find any kotlin native web scraping lib.
a
fat jars trash all the jar/module boundaries and need to handle things like merging resources and manifests: actually a pretty nasty hack, but one that’s become ubiquitous
j
Fat jar is hack? But even Google has mentioned it in its doc for Google Cloud Function https://github.com/GoogleCloudPlatform/functions-framework-java at the end “Specifying the right classpath can be tricky. A simpler alternative is to build the function as a “fat jar”, where the function code and all its dependencies are in a single jar file.”
No problem can continue to use shadow if need “fat jar”, just curious why its missing from the official gradle plugin to build and distribute JVM app. Thanks
c
The application plugin does not create a fat jar. It creates a zip that contains all the individual jars/resources of your application, making it easier to distribute, but the zip itself is not executable as a
java -jar
application. You’d have to use the Shadow plugin for that https://imperceptiblethoughts.com/shadow/introduction/