https://kotlinlang.org logo
#gradle
Title
# gradle
s

spierce7

02/15/2023, 4:57 PM
I need to get all my dependencies for a module into a single, runnable directory. This is part of a build pipeline I'm trying out, that runs my modules in docker. I'm aware of the Shadow Jar plugin, but that feels a little heavy for something that will run with every change. Plus the tool is using
rsync
which is smart enough to determine changes per file, so it's probably faster to have small class files, and jars from maven. What would be the best way to do this?
v

Vampire

02/15/2023, 5:05 PM
I would practically never use the shadow plugin for anything. You can use the
application
plugin to get a proper distributable archive (or directory) that then also is
rsync
friendly
m

mbonnin

02/15/2023, 5:05 PM
Grab the
runtimeClasspath
and copy all the jars somewhere?
Which is what
application
is doing under the hood I guess
v

Vampire

02/15/2023, 5:06 PM
Amongst other things, yes. It also creates start scripts for *nix and windows, provides tasks to create a distributable zip and tar.gz, ...
Just run the
installDist
task of the
application
plugin, then rsync the target directory of that task, by default
build/install/<appname>
a

Adam S

02/15/2023, 5:31 PM
there’s an example of how to manually create a fat jar in the docs https://docs.gradle.org/current/userguide/working_with_files.html#sec:creating_uber_jar_example, but I agree that the
application
plugin is best
v

Vampire

02/15/2023, 5:41 PM
If really needing to build a bad-practice fat jar, use the shadow plugin at least. It at least sails around some of the bloody pitfalls even if not around all. The example from the docs cares about none of them. A better way to build a fat jar would be like spring boot builds fat jars. But imho there is almost no case where a fat jar is a good idea. 🙂
s

spierce7

02/16/2023, 4:49 AM
wow -
installDist
seems like exactly what I was hoping for.
it's a bit odd, generating a shell script and a .bat file to fun the app.
v

Vampire

02/16/2023, 8:00 AM
Why is that odd? Usually you want to run your application.
e

eskatos

02/16/2023, 8:07 AM
If you are only interested in the distribution not the starting scripts you can stick with the
distribution
plugin https://docs.gradle.org/current/userguide/distribution_plugin.html
s

spierce7

02/17/2023, 3:51 AM
Just wasn't what I was expecting. I guess it's fine. I suppose without the shell script, running things directly with the
java
command would be difficult.
It makes sense
5 Views