Fork me on GitHub
#tools-build
<
2021-12-03
>
Joshua Suskalo17:12:51

Is there a good way to copy all of the dependencies to run a thin jar to a directory using the basis?

Joshua Suskalo17:12:39

The usecase here is setting up a dockerfile layer to contain all the dependencies for a jar produced from a polylith monorepo, so that in the final dockerfile will contain only the thin jar and its dependencies, and Docker will be able to cache all the dependencies between runs, but ideally without relying on just caching the .m2 directory and putting the entire monorepo into the image, because that will get large.

dominicm10:12:40

Fwiw, this is exactly how pack works out of the box! It's not tools.build compatible yet though (working on it!). We create the lib layers first, then the application layers.

hiredman17:12:04

It has been a while since I have thought about docker, but I don't believe having a thin jar vs an uberjar will improve Dockers caching between builds

Joshua Suskalo17:12:22

I've been told that in theory if only the thin jar has changed and the final docker image contains nothing but the dependencies and the thin jar, it should be able to cache the dependencies. If that's not the case then I can just move on with the uberjar.

hiredman17:12:38

I guess if you copy the deps in a separate layer from your thin jar

hiredman18:12:07

the thing to keep it mind is it won't all be jar files

hiredman18:12:22

there can be directories in there

hiredman18:12:33

and unless you specifically remove them from the deps information you calculate the basis from, it will include your source directories as well

hiredman18:12:35

it might be a good idea to pre-generate a file that contains the classpath as well, so you can easily launch with something like java -cp $(cat classpath-file) your.main.Class it is tempting to use java -cp whatever/* your.main.Class but using the globing might not put things on the classpath in the same order as tools.deps does

Joshua Suskalo19:12:34

Alright, thanks!