Search code examples
clojure

Why am i able to require in "src", but not in "core" directory in clojure?


I have have the following project structure:

--fourth (my project folder)

---core

----core.clj

----mycore.clj

core looks like this:

(ns core.core)

(require '[core.mycore :refer [myhello2]] :verbose)
(println "hi")

mycore looks like this:

(ns core.mycore)

(defn myhello2 []

  (println "hi")
  )

If i evaluate core.clj, i get the following error: Could not locate mycore__init.class, mycore.clj or mycore.cljc on classpath.

If i do the same and i just switch the "core" directory to "src", it works. What can i do, to make it work?

I tried to put {:depths ["core"]} in deps.edn, but nothing changed.

But my deps.edn is empty: {}


Solution

  • Per https://clojure.org/guides/tools_build, you want to use :path, not :depths (which I've never heard of / don't know to be valid at all) to specify the locations in your source tree from which to search for items.

    {
      :paths ["."]
    }
    

    ...means that core.mycore will be looked for in ./core/mycore.clj instead of ./src/core/mycore.clj (as is the case with the default :paths ["src"]).