Share your thoughts in the 2024 State of Clojure Survey!

Welcome! Please see the About page for a little more info on how this works.

+3 votes
in tools.deps by

This was hinted at in https://clojure.atlassian.net/browse/TDEPS-123?focusedCommentId=26919&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-26919

There are repos which contain many dependencies, where those dependencies in the repo are inter-dependent on each other. Currently there is no mechanism for consuming a dependency from a repo which is set up like that.

2 Answers

+1 vote
by

At Liftoff (liftoff.io), we have 34 clojure projects comprising over 1M lines of code. We use a monorepo and ran into the problem described in this thread while switching from leiningen to the Clojure CLI tools.

I think this issue could be addressed by turning relative paths into absolute paths upon reading the deps.edn files in clojure.tools.deps.alpha.reader/slurp-deps. Here is a short patch suggesting a fix for relative paths in :local/root coordinates.

Here is a full description of our use-case:

In a monorepo, the clojure CLI's config-dir deps.edn file might
contain relative paths to other parts of the repo.

For example, let's consider the following monorepo.


config/
  clojure/
    deps.edn
tools/
  lint/
    deps.edn
    src/...
  B/
    deps.edn
    src/..
A/
  deps.edn
  src/...

Let's image we want to add a repo-wide linting alias in
config/clojure/deps.edn.


{:aliases
   {:lint {:extra-deps {acme/lint {:local/root ../../tools/lint}}
           :main-opts ["-m" "acme.lint.core"]}}}

Developers set CLJ_CONFIG="config/clojure/deps.edn" in their shell
configuration. Clojure linting code lives at "tools/lint/deps.edn".

In all projects in the repo (e.g. at "A/deps.den", and
"tools/B/deps.den"), we would like clojure -A:lint to run the
linters.

Running clojure -A:lint in directory A, however, adds
"A/../../tools/lint/src" to the classpath, rather than
"A/../tools/lint/src" or "/path/to/repo/tools/lint/src".

Thank you to the clojure team for the incredible work you've been doing over the years!

by
We also have a monorepo with several dozen subprojects and we use CLI/deps.edn exclusively.

What we've done is to ensure all the subprojects are at the same depth from the root of the repo and then all the relative paths work, assuming you run clojure in the subproject folder (containing the local deps.edn) and use CLJ_CONFIG=../../path/to/config as the relative path to the folder containing the control/default/override deps.edn.

Having all the subprojects at the same depth makes things a lot simpler for tooling because given just a subproject name, the (relative) path to it is predictable from any other subproject.

That said, addressing the "relative to the deps.edn file" aspect of :local/root would be beneficial to a lot of people I suspect.
by
I understand where you're coming from, but this doesn't seem like the best solution to it (seems like it likely could cause other problems with relative resolution).
by
Just for my clarification Alex, are :local/root paths considered relative to the deps.edn in which they are found or are they still relative to the project in which clojure is executed?

I'm hazy on the history there but it feels like it used to be the latter and that was considered a bug but I don't know if there was a change of behavior?

For us, it doesn't matter: our :local/root paths are relative in such a way that it doesn't matter which subproject we're in when we run clojure (that's why we have all the subprojects at the same level).
by
Correct, it was the latter, which was a bug, and is now the former.
by
Perfect! Thank you. Glad to know I'm not going senile (well... :) )
0 votes
by
Reference: https://clojure.atlassian.net/browse/TDEPS-132 (reported by severeoverfl0w)
...