0

I am trying to link a local project to another local project that is under development using tools.deps :local/root option in deps.edn. It isn't working. I can't require the library's namespaces, and the path is correct.

The deps.edn entry looks like:

{:paths ["src" "resources"]
 :deps {...
        ...
        ...
        mylib {:local/root "../../../mylib"}
}}

The classpath that is generated, however, is incorrect:

../../../mylib/src/main/clojure

For some reason clojure/main is added on to the classpath for this library, and I don't know why. Then when I run clj to start the repl I am unable to load the library, and I get the FileNotFoundException.

To test that the addition of main/clojure to the lib path is the problem, I manually removed that part of the path in the cache file in .cpcache directory and was able to require the library namespaces once I'd removed clojure/main.

Does anyone know where the main/clojure is coming from and how I can stop it being added?

UPDATE

I did a new test that leads me to think this has something to do with the use of project.clj as opposed to deps.edn in the target project. In the test I had a project b with a deps.edn like this:

{:deps {a-proj {:local/root "../a-proj"}}}

While a-proj had a project.clj like this:

(defproject a-proj "0.1.0-SNAPSHOT"
  :description "blah"
  :url "http://example.com/FIXME"
  :license {:name "The MIT Licence"
            :url "https://opensource.org/licenses/MIT"}

  :source-paths ["src"]

  :dependencies [])

I then ran clj -Sforece -Spath and got:

~/Projects/b > clj -Sforce -Spath ethan at rembrandt.local src:/Users/ethan/.m2/repository/org/clojure/clojure/1.10.0/clojure-1.10.0.jar:/Users/ethan/Projects/b/src:/Users/ethan/Projects/a-proj/src/main/clojure:/Users/ethan/.m2/repository/org/clojure/spec.alpha/0.2.176/spec.alpha-0.2.176.jar:/Users/ethan/.m2/repository/org/clojure/core.specs.alpha/0.2.44/core.specs.alpha-0.2.44.jar

You can see there that the /main/clojure path has been aded on. When I instead use an essentially deps.edn in a-proj:

{:deps {}}

I get the following path, which seems correct:

~/Projects/b > clj -Sforce -Spath
src:/Users/ethan/.m2/repository/org/clojure/clojure/1.10.0/clojure-1.10.0.jar:/Users/ethan/Projects/b/../a-proj/src:/Users/ethan/.m2/repository/org/clojure/spec.alpha/0.2.176/spec.alpha-0.2.176.jar:/Users/ethan/.m2/repository/org/clojure/core.specs.alpha/0.2.44/core.specs.alpha-0.2.44.jar

My deps.edn in ~/.clojure has only this:

{
 :aliases {
          :new {:extra-deps {seancorfield/clj-new {:mvn/version "0.9.0"}}
                  :main-opts ["-m" "clj-new.create"]}
          :deps {:extra-deps {org.clojure/tools.deps.alpha {:mvn/version "0.5.435"}}}
          :test {:extra-paths ["test"]}
  }
}
fraxture
  • 5,113
  • 4
  • 43
  • 83
  • You'll need to provide more details about your deps.edn file and what commands you are trying to execute in order for folks to help you. – Sean Corfield May 03 '21 at 05:20
  • @SeanCorfield I added some info about the deps.edn. I'm not really running any commands other than running the repl within the project. What other information might be relevant? – fraxture May 03 '21 at 06:01
  • Have you added `clojure/main` as `:paths` in mylib? Trying to reproduce this locally with `1.10.3.822` and `clj -Spath` shows the proper path (and no `clojure/main`). – cfrick May 03 '21 at 10:40
  • Thank you for taking a crack @cfrick. One other detail here is that `mylib` uses `project.clj`. It's `project.clj` has `:source-paths ["src"]` set, and you can see that in the pom.xml file. – fraxture May 03 '21 at 14:28
  • I think it's somehow related to the use of project.clj. I did a super simple test with two projects and it showed up when I used a project.clj in the local project specified by `:local/root`. – fraxture May 03 '21 at 15:41
  • `project.clj` is for Leiningen. `deps.edn` is for the Clojure CLI. If you're seeing this in a project without `deps.edn` then the problem is most likely in your user `deps.edn` which will either be in a `.clojure` folder in your home directory (most systems) or in a `.config/clojure` folder on XDG-style systems. Can you share some of your user `deps.edn` file? – Sean Corfield May 04 '21 at 17:07
  • Added @SeanCorfield. – fraxture May 05 '21 at 05:17
  • You cannot depend (via :local/root) on a Leiningen project. You can only depend on a project that has deps.edn or pom.xml. – Sean Corfield May 06 '21 at 06:26
  • @SeanCorfield Interesting. Technically, the dependency does have a pom.xml, which is produced when I run `lein install` in that project's root. But are you generally saying that `:local/root` does support leinigen projects? What I don't understand is that it seems to work fine if I manually remove `main/clojure` from the classpath in `.cpcache`. – fraxture May 06 '21 at 16:26

1 Answers1

1

project.clj is not supported as a project type by the Clojure CLI via deps.edn.

Alex Miller
  • 69,183
  • 25
  • 122
  • 167