# What's the right way to hot-reload dependencies without restarting the repl?

**URL:** https://clojureverse.org/t/whats-the-right-way-to-hot-reload-dependencies-without-restarting-the-repl/5357
**Category:** How to?
**Created:** [January 12, 2020, 4:02pm UTC](https://clojureverse.org/t/whats-the-right-way-to-hot-reload-dependencies-without-restarting-the-repl/5357 "2020-01-12T16:02:34Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![sound2gd](https://clojureverse.org/user_avatar/clojureverse.org/sound2gd/32/2785_2.png) [@sound2gd](https://clojureverse.org/u/sound2gd)
#### Post date: [January 12, 2020, 4:02pm UTC](https://clojureverse.org/t/whats-the-right-way-to-hot-reload-dependencies-without-restarting-the-repl/5357/1 "2020-01-12T16:02:34Z")

</div>

I use leiningen, Emacs and cider.

clojure repl starting very slow, the question is how to **add dependencies** on the fly.

I’ve tried [pomegranate](https://github.com/clj-commons/pomegranate), it seems only worked at current repl session.

---

<div class="post-metadata">

### Author: ![didibus](https://clojureverse.org/user_avatar/clojureverse.org/didibus/32/951_2.png) [@didibus](https://clojureverse.org/u/didibus)
#### Post date: [January 13, 2020, 2:24am UTC](https://clojureverse.org/t/whats-the-right-way-to-hot-reload-dependencies-without-restarting-the-repl/5357/2 "2020-01-13T02:24:54Z")

</div>

> [@sound2gd](#):
>
> I’ve tried [pomegranate](https://github.com/clj-commons/pomegranate), it seems only worked at current repl session

What do you expect it to work at beyond the current repl session?

---

<div class="post-metadata">

### Author: ![sound2gd](https://clojureverse.org/user_avatar/clojureverse.org/sound2gd/32/2785_2.png) [@sound2gd](https://clojureverse.org/u/sound2gd)
#### Post date: [January 13, 2020, 4:52am UTC](https://clojureverse.org/t/whats-the-right-way-to-hot-reload-dependencies-without-restarting-the-repl/5357/3 "2020-01-13T04:52:27Z")

</div>

yes, is there a way to do so?

---

<div class="post-metadata">

### Author: ![mvarela](https://clojureverse.org/user_avatar/clojureverse.org/mvarela/32/1478_2.png) [@mvarela](https://clojureverse.org/u/mvarela)
#### Post date: [January 13, 2020, 7:56am UTC](https://clojureverse.org/t/whats-the-right-way-to-hot-reload-dependencies-without-restarting-the-repl/5357/4 "2020-01-13T07:56:54Z")

</div>

You just need to add the dependencies to your project.clj file, to use them in the next REPL session.

---

<div class="post-metadata">

### Author: ![teodorlu](https://clojureverse.org/user_avatar/clojureverse.org/teodorlu/32/2896_2.png) [@teodorlu](https://clojureverse.org/u/teodorlu)
#### Post date: [January 13, 2020, 1:51pm UTC](https://clojureverse.org/t/whats-the-right-way-to-hot-reload-dependencies-without-restarting-the-repl/5357/5 "2020-01-13T13:51:46Z")

</div>

I’m reading @sound2gd’s question as “What’s a workflow with hot-reloaded dependencies that works well”. Which I’m also interested in. Perhaps a wrapper around Pomegranate that also edits your `project.clj` or `deps.edn` file would be nice.

`clj -A:find-deps` at [https://github.com/hagmonk/find-deps](https://github.com/hagmonk/find-deps) might be worth looking at – it’s rewriting `deps.edn` files.

---

<div class="post-metadata">

### Author: ![sound2gd](https://clojureverse.org/user_avatar/clojureverse.org/sound2gd/32/2785_2.png) [@sound2gd](https://clojureverse.org/u/sound2gd)
#### Post date: [January 13, 2020, 2:34pm UTC](https://clojureverse.org/t/whats-the-right-way-to-hot-reload-dependencies-without-restarting-the-repl/5357/6 "2020-01-13T14:34:43Z")

</div>

bravo, that’s what I want.

I think this should be a basic feature of “REPL driven development”.

once you open the REPL, you can interactively do anything your mind goes, withouting exiting the creative flow.

---

<div class="post-metadata">

### Author: ![didibus](https://clojureverse.org/user_avatar/clojureverse.org/didibus/32/951_2.png) [@didibus](https://clojureverse.org/u/didibus)
#### Post date: [January 13, 2020, 6:00pm UTC](https://clojureverse.org/t/whats-the-right-way-to-hot-reload-dependencies-without-restarting-the-repl/5357/7 "2020-01-13T18:00:05Z")

</div>

Ya, I don’t think I know of something that will update your lein profiles and pull in the dependencies into the running REPL all together.

Normally I add my dependencies to the user or repl profile [https://github.com/technomancy/leiningen/blob/master/doc/PROFILES.md#default-profiles](https://github.com/technomancy/leiningen/blob/master/doc/PROFILES.md#default-profiles) which I want to have available globally.

So I might use pomegranate to try out libs, and when I find something I like, I’d update my user or repl profile with it.

I also go and update my deps.edn repl alias, because I often use both lein and clj.

When in Emacs though, you need to specify to Emacs that you want to use the repl alias when jacking in by setting: `cider-clojure-cli-global-options`. Otherwise it won’t use an alias.

In lein, the user profile is always merged in. Can’t remember if cider-jack-in uses the repl profile by default, but that could also be configured using `cider-lein-global-options` in cider.

Here’s the doc for cider Jack in: [https://docs.cider.mx/cider/basics/up\_and\_running.html](https://docs.cider.mx/cider/basics/up_and_running.html)

An alternative to all the above, is that you can instead add pomegranate as a dependency in your lein user profile and your deps alias which you’ve configured Cider to use.

And then you can also add a dependency on: [https://github.com/gfredericks/user.clj](https://github.com/gfredericks/user.clj) as well to both these places.

Now, you can create a global user.clj which both lein and clj will use when starting a repl. In that user.clj, you can then add pomegranate code to pull in dependencies on load. With that options, you only need to modify your user.clj overtime as you pull in more and more deps. And it feels a bit like doing everything at the repl, since you can add pomegranate code to your user.clj, eval it, and if you like it just save it and it’ll persist beyond your current repl session.

---

<div class="post-metadata">

### Author: ![sound2gd](https://clojureverse.org/user_avatar/clojureverse.org/sound2gd/32/2785_2.png) [@sound2gd](https://clojureverse.org/u/sound2gd)
#### Post date: [January 14, 2020, 3:24pm UTC](https://clojureverse.org/t/whats-the-right-way-to-hot-reload-dependencies-without-restarting-the-repl/5357/8 "2020-01-14T15:24:45Z")

</div>

> [@didibus](#):
>
> Now, you can create a global user.clj which both lein and clj will use when starting a repl. In that user.clj, you can then add pomegranate code to pull in dependencies on load. With that options, you only need to modify your user.clj overtime as you pull in more and more deps. And it feels a bit like doing everything at the repl, since you can add pomegranate code to your user.clj, eval it, and if you like it just save it and it’ll persist beyond your current repl session.

thanks, but maybe user.clj solution is not what I expected.  
I expect this:

> [@teodorlu](#):
>
> What’s a workflow with hot-reloaded dependencies that works well

my daily routine:

1. run `lein repl`
2. eval some code with cider, find some lib interesting, add to project.clj
3. stop repl, re-run `lein repl`

this needs improvements. such as not stop repl , just hot-reload it.  
and cider recognize it, auto-complete functions or methods that lib provides, and eval code that use that lib.

---

<div class="post-metadata">

### Author: ![didibus](https://clojureverse.org/user_avatar/clojureverse.org/didibus/32/951_2.png) [@didibus](https://clojureverse.org/u/didibus)
#### Post date: [January 14, 2020, 9:03pm UTC](https://clojureverse.org/t/whats-the-right-way-to-hot-reload-dependencies-without-restarting-the-repl/5357/9 "2020-01-14T21:03:26Z")

</div>

> this needs improvements. such as not stop repl , just hot-reload it.

That’s what pomegranate does?

1. Run lein repl
2. Connect to it from Cider
3. Open user.clj
4. Add your dependencies to pomegranate:

```auto
(add-dependencies :coordinates '[[cool-lib-i-found "1.2.2"]]
                  :repositories (merge cemerick.pomegranate.aether/maven-central
                                       {"clojars" "https://clojars.org/repo"}))

```

1. Eval user.clj
2. C-X-S to save user.clj

Now your new lib is available inside your current Cider REPL, with auto-complete, doc, etc.

If you restart the repl, or your computer, etc, basically next time you run lein repl, user.clj will run again so your lib will be there as well.

---

<div class="post-metadata">

### Author: ![sound2gd](https://clojureverse.org/user_avatar/clojureverse.org/sound2gd/32/2785_2.png) [@sound2gd](https://clojureverse.org/u/sound2gd)
#### Post date: [January 15, 2020, 1:37am UTC](https://clojureverse.org/t/whats-the-right-way-to-hot-reload-dependencies-without-restarting-the-repl/5357/10 "2020-01-15T01:37:46Z")

</div>

> [@didibus](#):
>
> That’s what pomegranate does?

since 1.0.0, pomegranate can not achieve that 🤣

---

<div class="post-metadata">

### Author: ![didibus](https://clojureverse.org/user_avatar/clojureverse.org/didibus/32/951_2.png) [@didibus](https://clojureverse.org/u/didibus)
#### Post date: [January 15, 2020, 2:21am UTC](https://clojureverse.org/t/whats-the-right-way-to-hot-reload-dependencies-without-restarting-the-repl/5357/11 "2020-01-15T02:21:47Z")

</div>

Works for me, are you using: [https://github.com/clj-commons/pomegranate](https://github.com/clj-commons/pomegranate) ?

This is what I have in my user.clj:

```auto
(require '[cemerick.pomegranate :as pomegranate :refer (add-dependencies)])

(let [cl (.getContextClassLoader (Thread/currentThread))]
  (.setContextClassLoader (Thread/currentThread) (clojure.lang.DynamicClassLoader. cl))
  (add-dependencies :coordinates '[[com.rpl/defexception "0.1.0"]
                                   [com.rpl/proxy-plus "0.0.1"]]
                    :repositories (merge cemerick.pomegranate.aether/maven-central
                                         {"clojars" "https://clojars.org/repo"})))

```

Using Java 8.

I tried it with:

```auto
[com.rpl/defexception "0.1.0"]
[com.rpl/proxy-plus "0.0.1"]

```

I started without them defined in pomegranate. Opened my user.clj, added them, pressed C-x C-k to eval user.clj again. It pulled in both dependencies dynamically into my repl. I was then able to require them and use them directly, with auto-complete and eveything (except the namespace didn’t auto-complete until I required it).

I then did C-x C-s to save my user.clj. I killed the repl, and started a repl again, connected to it from Cider, and tried to require defexception, and it worked.

---

<div class="post-metadata">

### Author: ![lins05](https://clojureverse.org/user_avatar/clojureverse.org/lins05/32/2414_2.png) [@lins05](https://clojureverse.org/u/lins05)
#### Post date: [January 17, 2020, 2:23pm UTC](https://clojureverse.org/t/whats-the-right-way-to-hot-reload-dependencies-without-restarting-the-repl/5357/12 "2020-01-17T14:23:17Z")

</div>

Last time I tried it, there was a bug in the current lein repl. Something like this [https://github.com/nrepl/nrepl/issues/113](https://github.com/nrepl/nrepl/issues/113)

---

<div class="post-metadata">

### Author: ![system](https://clojureverse.org/uploads/default/original/2X/5/51079bf9e4b7d9466242c06cf1e43b9f8bd6da14.png) [@system](https://clojureverse.org/u/system)
#### Post date: [July 18, 2020, 2:29am UTC](https://clojureverse.org/t/whats-the-right-way-to-hot-reload-dependencies-without-restarting-the-repl/5357/13 "2020-07-18T02:29:27Z")

</div>

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.
