Skip to content

Instantly share code, notes, and snippets.

@realgenekim
Last active July 21, 2023 14:29
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save realgenekim/97cd8da28b00761560bef06b8072eb9f to your computer and use it in GitHub Desktop.
Save realgenekim/97cd8da28b00761560bef06b8072eb9f to your computer and use it in GitHub Desktop.
How to download all Clojure dependencies using clj (equivalent to "lein deps")

I recently had to figure out for a Clojure application how to download all dependency JAR files, for use in a Docker container.

When creating an uberjar, depstar re-downloaded all the external dependencies from Maven central, even though in an earlier Docker build step, I ran clj -Spath to pre-download them (presumably cached into the .m2 directory). In the past, I've used lein deps to do something similiar.

I'm grateful for Sean Corfield helping out (again!!): In short, use clj -P (short for "prepare") to download dependencies. Note the "A:depstar" option, which ensures that the depstar dependencies are downloaded, too.

Here's what it looks like in a Dockerfile:

# to pre-download dependencies, only done if deps.edn changes
RUN mkdir /tmp/pubsub-web
COPY ./pubsub-web/deps.edn /tmp/pubsub-web
WORKDIR /tmp/pubsub-web
RUN clj -P
RUN clj -A:depstar -P
@realgenekim
Copy link
Author

Many thanks to @seancorfield for his help on Clojurians channel, and his work on depstar.

He pointed me at this issue that would have helped: seancorfield/depstar#74

And the documentation for Clojure prepare flag ("-P"): https://clojure.org/reference/deps_and_cli#_prepare_for_execution

(think lein deps)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment