Teodor
Teodor

Reputation: 759

What do Clojure deps.edn :deps keys mean?

Trying to use Clojure Deps and CLI, I was surprised to find out that the following all worked for using clojure.data.json.

Maven dependency:

{:deps {org.clojure/data.json {:mvn/version "0.2.6"}}}

Git dependency with same key:

{:deps {org.clojure/data.json {:git/url "https://github.com/clojure/data.json.git"
                               :sha "13e9d244678be7b235bb24a10310f9d147ea088d"}}}

Git dependency with random key:

{:deps {lol/this-works {:git/url "https://github.com/clojure/data.json.git"
                        :sha "13e9d244678be7b235bb24a10310f9d147ea088d"}}}

With Maven and Clojars dependencies, :deps keys identify the artifact. When using a git sha instead, the name doesn't seem to matter.

Resources I've read but may contain what I'm after:

Upvotes: 2

Views: 659

Answers (1)

rdgd
rdgd

Reputation: 1446

It would seem that this is a result of how the git "extension" is handled in the tooling when compared to other "extensions" like maven. All the relevant code for this can be found here. I'll also make it clear that I haven't read this code in depth, and so my knowledge of this code therefore is not deep.

If you look at the way the lib is treated in the maven extension for example, it appears that it is actually checking maven to see that the artifact exists by the name supplied, which you can see in more than one place, but also including in the multimethod definition of ext/canonicalize :mvn

In the git extension code, the lib is given a different treatment, which you can see in the multimethod definition of ext/canonicalize :git

I don't want to get too deep into the realm of conjecture here, but I would guess that if this was an intentional design decision, it probably has something to do with the notion of the address of a git repo being the SoT for those kind of dependencies (even though the address/name of the repo can change... danger!), whereas in Maven names are registered first-class citizens.

And to try to more directly answer your two questions... What do the :deps keys mean? The simple answer is it depends on what kind of dep it is! When using git, it can be whatever, and when using Maven for example it must reference a known package. How should I choose my dep keys? This has the danger of being subjective, however, I would recommend tending to use any dep that has a reliable immutable repository of packages behind it, and only when needed use a dep like github. This is because github dependencies can change their address/name, or simply vanish into thin air (deleted repository).

Upvotes: 2

Related Questions