tools-build

2021-12-03T17:30:51.300100Z

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

2021-12-03T17:44:39.302500Z

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.

dominicm 2021-12-05T10:02:40.316Z

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.

2021-12-03T17:53:04.305Z

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

2021-12-03T17:54:22.306Z

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.

2021-12-03T17:59:38.307300Z

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

2021-12-03T18:03:43.307700Z

https://github.com/clojure/tools.deps.alpha/blob/master/src/main/clojure/clojure/tools/deps/alpha.clj#L793 classpath-roots is what you want from the basis

2021-12-03T18:04:07.308100Z

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

2021-12-03T18:04:22.308400Z

there can be directories in there

2021-12-03T18:05:33.309600Z

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

2021-12-03T18:10:35.312200Z

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

2021-12-03T19:02:34.312400Z

Alright, thanks!