clojure

How can new clojure libraries be loaded in the repl


So I have this workflow problem:

I'm happily typing away on my clojure project repl and realise that i need another library that is not in my project.clj, say in this case, i needed the tools.cli library.

I open up project.clj in my editor and add in an entry to the :dependencies

     [org.clojure/tools.cli "0.2.1"]

Then, within the project directory, I type lein deps in the shell to pull in the necessary libraries

After the project dependencies are pulled, technically all the class files are already there ready to be loaded, but if I go back to my repl and type:

> (use 'tools.cli)

I get this:

=>> FileNotFoundException Could not locate tools/cli__init.class
  or tools/cli.clj on classpath:   clojure.lang.RT.load (RT.java:432)

So I would have to restart my repl, wasting a whole heap of time reconfiguring the state of the repl to where I was before I needed the library.

Is there a way to just load in the library dynamically? eg, after I run lein deps I just go back to the repl and type:

> (load-library "tools.cli") 
> (use 'tools.cli)

Thanks in advance


Solution

  • Pomegranate is for you:

    https://github.com/cemerick/pomegranate

    It supports download and addition of new dependencies at runtime, e.g.:

    (add-dependencies :coordinates '[[incanter "1.2.3"]]
                      :repositories (merge cemerick.pomegranate.aether/maven-central
                                           {"clojars" "http://clojars.org/repo"}))