I need to get all my dependencies for a module int...
# gradle
s
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
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
Grab the
runtimeClasspath
and copy all the jars somewhere?
Which is what
application
is doing under the hood I guess
v
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
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
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
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
Why is that odd? Usually you want to run your application.
e
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
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