Why is clojure deps adding `/main/clojure` to classpath when using `:local/root`?

317 Views Asked by At

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"]}
  }
}
1

There are 1 best solutions below

0
On

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