Skip to content

Instantly share code, notes, and snippets.

@worace
Created December 4, 2015 21:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save worace/742d73e8d27a46ad759c to your computer and use it in GitHub Desktop.
Save worace/742d73e8d27a46ad759c to your computer and use it in GitHub Desktop.
Hotloading Dependencies in Leiningen with refactor-nrepl

Hotloading Deps in Lein

Refactor nrepl makes it possible to hotload a dependency into lein without rebooting the repl. This is awesome but it's not super well documented.

First, make sure you have the plugin installed by adding it to the :plugins key of your lein profile. This can be done per project in project.clj, but is probably best to include in your ~/.lein/profiles.clj

Here's an example:

{:user {:plugins [[refactor-nrepl "1.1.0"]
        :dependencies [[alembic "0.3.2"]
                       [org.clojure/tools.namespace "0.2.11"]
                       [org.clojure/tools.nrepl "0.2.7"]]
        }
 }

Now, from a REPL session you can hotload like this:

(refactor-nrepl.artifacts/hotload-dependency {:coordinates "[pandect \"0.5.4\"]"})

Notice that the argument is a map with a key of :coordinates and a value which is an EDN string of the lein dependency vector representing the library you want to load. Not sure why this can't be passed is a quoted form, but the refactor-nrepl library reads it using edn/read-string, so you need to use the string format.

@LouDnl
Copy link

LouDnl commented Nov 14, 2022

Wanted to try this but got thrown an exception and only then I realized this gist is from 7 years ago 🤷‍♂️

; Execution error (IllegalArgumentException) at refactor-nrepl.artifacts/hotload-dependency (artifacts.clj:161).
; Temporarily disabled until a solution for java 10 is found.

@worace
Copy link
Author

worace commented Nov 14, 2022

ha yeah sorry @LouDnl glad you found this gist but it's been a long time and I'm sure all the related clojure tooling has moved a lot since then.

@LouDnl
Copy link

LouDnl commented Nov 14, 2022

Indeed it did, I found what I needed in the end. Thanks for your reply @worace !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment