Reputation: 4564
Started playing with Clojure yesterday. I can't get around how the module system works:
/src/clojure_first_steps
core.clj
(ns clojure-first-steps.core)
(:require [clojure-first-steps.utils :refer :all])
(defn run-other-foo
(foo-2 ["hello"]))
utils.clj
(ns clojure-first-steps.utils)
(defn foo-2 [x] (x))
although 'lein compile' runs without probs, 'lein test' fails to compile on
(:require [clojure-first-steps.utils :refer :all])
, the test being:
(ns clojure-first-steps.core-test
(:require [clojure.test :refer :all]
[clojure-first-steps.core :refer :all]))
(deftest a-test
(testing "I can access dependecies from another module"
(is (= "hello" (run-other-foo)))))
The error message is java.lang.ClassNotFoundException: clojure-first-steps.utils
EDIT: Project tree
.
├── CHANGELOG.md
├── clojure_first_steps.iml
├── doc
│ └── intro.md
├── LICENSE
├── project.clj
├── README.md
├── resources
├── src
│ ├── clojure_first_steps
│ │ ├── core.clj
│ │ └── utils.clj
├── target
│ ├── classes
│ │ └── META-INF
│ │ └── maven
│ │ └── clojure_first_steps
│ │ └── clojure_first_steps
│ │ └── pom.properties
│ ├── repl-port
│ └── stale
│ └── leiningen.core.classpath.extract-native-dependencies
└── test
├── clojure_first_steps
│ └── core_test.clj
Upvotes: 0
Views: 44
Reputation: 20194
In your core.clj:
(ns clojure-first-steps.core)
(:require [clojure-first-steps.utils :refer :all])
This is incorrect - the (:require)
clause needs to be inside the ns
macro. Because it is not, the symbols in the vector are looked up (and obviously not found).
(ns clojure-first-steps.core
(:require [clojure-first-steps.utils :refer :all]))
This tells the Clojure compiler to load clojure-first-steps.utils
(if it has not already), and refer it's definitions in your newly created namespace.
Upvotes: 2