How do I update Clojure dependencies when working with nrepl.el?
Asked Answered
L

4

21

As I understand it, when I do nrepl-jack-in a REPL is loaded along with all the dependencies defined in project.clj. If I then update project.clj to add a new dependency, do I need to kill the server and re-run nrepl-jack-in or is there way to update the dependencies in the current REPL?

Litton answered 8/2, 2013 at 19:3 Comment(0)
G
7

Update: Maybe there is some hope, See https://github.com/cemerick/pomegranate

Previously:

The short answer is yes - you do have to restart the JVM process.

I am aware of no good way to update dependencies in a live repl. Leiningen (called by nrepl-jack-in) will manage dependencies and set up the classpath only upon restarting. Trying to do something dynamic and clever is horribly fragile.

The struck out text below is factually true but upon a moment's reflection seemed such bad advice I have marked it up as such...

If you have a local dependency (e.g. jar file) you might use the long-time deprecated function add-classpath at the repl. But you will be entering the dragon infested swamp of java classloaders.

Guam answered 8/2, 2013 at 19:59 Comment(2)
does the usefulness of cemeric/pomegranate appear when the hassle of reloading the cider process is much greater than the hassle of pomegranate?Creditable
@ErikAllik Yes. For example, when tinkering/exploring in a data analysis context - a bunch of 'state' might be built up in terms of data cleaning, normalization etc. Not having to re-run all the work to get to that state just to try a different model or visualization library can be a nice convenience. Oh course the discipline to have a proper reproducible analysis demands restarting and working to make things cleanly re-runnable too.Guam
B
4

Restarting the REPL seems to be the simplest way. This can be done with:

M-x cider-restart

That also appears to accomplish a lein deps. So the whole process of adding a new dependency simply involves adding the require to your project.clj and then invoking cider-restart.


Another (very convenient) way is to use clj-refactor. Adding the artifact (C-c m a p or cljr-add-project-dependency) will prompt for the version you want, automatically put the new dependency into your project.clj file, and reload your session.

Brecciate answered 24/6, 2016 at 23:29 Comment(3)
For me running cider-restart does not update the dependencies described in project.clj.Makell
@Micah Elliott, can you please elaborate more on the 2nd way? Not sure I understand. cljr-add-project-dependency works great for adding new deps but my running cider repl wasn't reloaded and new dependency is unreachable. Although I didn't use clj-refactor.. not sure how it is related to cider repl restarts.Boxboard
Neither of these work for me. I have to cider-quit and cider-jack-in again. clj-refactor makes adding the dependency to project.clj much more convenient though.Inessential
P
1

Before pomegranate existed, I wrote my own library to dynamically load dependencies.

https://github.com/bmillare/dj

After the release of lein2 and how it under the covers can use pomegrante, I rewrote dj to use this underneath. So, even if you don't use 'dj', it might be a useful as a reference to see what its doing.

Preselector answered 9/2, 2013 at 0:30 Comment(0)
P
0

With Clojure 1.12.0-alpha2, add-lib could download new library.

Phlebotomy answered 6/7 at 18:37 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Preference

© 2022 - 2024 — McMap. All rights reserved.