Any way to add dependency to lein project without REPL restart?

10,305

Solution 1

You can use Alembic, a dynamic classpath loader and dependencies resolver. The good thing is that it doesn't load all pomegranate dependencies.

Add the following to your .lein/profiles.clj:

{:user
  {:dependencies [[alembic "0.3.2"]]}}

Then in your Repl just load the classpaths you need, they will be pulled from the repositories by leinif need:

(require 'alembic.still)
(alembic.still/distill '[enlive "1.1.5"])

(require 'net.cgrand.enlive-html) should now work.

Solution 2

for quick testing you can use pomegranate to add dependencies on the fly

=> (use '[cemerick.pomegranate :only (add-dependencies)])
nil
=> (add-dependencies :coordinates '[[incanter "1.2.3"]])

for actually adding a dependency I ususally hit

  • Alt-x nrepl-restart
  • ctrl-cctrl-k to reload the file,
  • ctrl-calt-n to get back to the namespace i in the buffer

The whole process takes the jvm startup time (which i agree is a touch painful) plus five seconds. It helps to keep your project in a state where loading a file does all the require initialization.

Share:
10,305

Related videos on Youtube

LoveProgramming
Author by

LoveProgramming

Updated on December 17, 2020

Comments

  • LoveProgramming
    LoveProgramming over 3 years

    What I do now is open project.clj, add dependency there, run lein deps restart repl, then use, require and so on.

    The thing is that I don't really like to restart repl because the startup time is slow and I have to reload my files again.

    So is there a better way to add dependency to lein project? without restarting the repl?

  • LoveProgramming
    LoveProgramming almost 11 years
    Thanks! this is exactly what I was looking for
  • Michał Marczyk
    Michał Marczyk almost 11 years
    Oh wow, missed this while writing essentially the same answer. +1.
  • i-blis
    i-blis almost 8 years
    @Kolja, Thanks for spotting the typo.