Ask coding questions

← Back to all posts
clojure dependencies
sunj (7)

How do I specify dependencies from

PYer (4017)

Also, you should specify what language.

ash15khng (724)

@fullern000 He did, in the title of the post it says "clojure" which is a language supported on [] apparently. Guess you learn something new everyday.

PYer (4017)

What is a dependency?


Yeah, what is it?

coalesce (3)

@fullern000 The same as in Node and Python - internal and external .clj files which are plugged in to code like this (this file should be in classpath of JVM)

(ns example.core
  (:require [somelib.core :as smlibalias]))
ryuhcii (1)

+1 for this.
I needed to use and couldn't find a way how to add dependencies in

AlexAti (0)

Hopefully in the near future it will be as simple as evaluating the following:

(add-lib 'org.clojure/core.memoize {:mvn/version "0.7.1"})


jclavijo (0)

Found a work around.
First you can't name any other file .clj if you want to see the output of the main.clj when you hit run. You can use files with no extensions. So core.clj would be just core and if you put the file in a folder, (ex. "proj/"), also leave no extension in the filename. Using (ns proj.core) will work fine.
Second, use load-file in the main.clj . (load-file "proj/core") before calling
(require 'proj.core) or before using

(ns main
      (:require [proj.core :refer :all]))

That should be enough to call dependencies from files you wrote or created that are not in the version of clojure being used.
Last pro-tip, if you want to build while testing, simply build the file in whatever folder and file structure, load it, require it, and run-test definitions for the ns or from the main.clj

(load-file "proj/core_test")
(require 'clojure.test)
(clojure.test/run-tests 'proj.core_test)
jclavijo (0)

Yea... it seems to be a bug or overlooked component. It might also be that since main is executed and the repl is loaded, any dependencies that are outside of the clojure version running can't be loaded, but it also prevents files created adjacent in the project from being used as dependencies

obiSerra (0)

I had the same problem and I ended up uploading the source code of the library I needed (it was core.match)

coalesce (3)

For me it seems that in only Node and Python is extendable with external libs :(