简体   繁体   English

在使用nrepl.el时如何更新Clojure依赖项?

[英]How do I update Clojure dependencies when working with nrepl.el?

As I understand it, when I do nrepl-jack-in a REPL is loaded along with all the dependencies defined in project.clj. 据我了解,当我执行nrepl-jack-in ,REPL与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? 如果我然后更新project.clj以添加新的依赖项,我是否需要nrepl-jack-in服务器并重新运行nrepl-jack-in或者是否有办法更新当前REPL中的依赖项?

Update: Maybe there is some hope, See https://github.com/cemerick/pomegranate 更新:也许有一些希望,请参阅https://github.com/cemerick/pomegranate

Previously: 先前:

The short answer is yes - you do have to restart the JVM process. 简短的回答是肯定的 - 您必须重新启动JVM进程。

I am aware of no good way to update dependencies in a live repl. 我知道没有好的方法来更新实时repl中的依赖项。 Leiningen (called by nrepl-jack-in) will manage dependencies and set up the classpath only upon restarting. Leiningen(由nrepl-jack-in调用)将管理依赖项并仅在重新启动时设置类路径。 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 (eg jar file) you might use the long-time deprecated function add-classpath at the repl. 如果您有本地依赖项(例如jar文件),则可以在repl中使用长时间 不推荐使用的函数 add-classpath But you will be entering the dragon infested swamp of java classloaders. 但是你将进入龙类肆虐的java类加载器沼泽。

Before pomegranate existed, I wrote my own library to dynamically load dependencies. 在石榴存在之前,我编写了自己的库来动态加载依赖项。

https://github.com/bmillare/dj 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. 在lein2发布之后以及如何在封面下使用pomegrante,我重写了dj以便在下面使用它。 So, even if you don't use 'dj', it might be a useful as a reference to see what its doing. 所以,即使你不使用'dj',它也可能是一个有用的参考,看看它在做什么。

Restarting the REPL seems to be the simplest way. 重启REPL似乎是最简单的方法。 This can be done with: 这可以通过以下方式完成:

M-x cider-restart

That also appears to accomplish a lein deps . 这也似乎完成了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 . 因此,添加新依赖项的整个过程只需将require添加到project.clj ,然后调用cider-restart


Another (very convenient) way is to use clj-refactor . 另一种(非常方便)的方法是使用clj-refactor Adding the artifact ( Cc map 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 . 添加工件Cc mapcljr-add-project-dependency )将提示您所需的版本, 自动将新的依赖项放入project.clj文件,然后重新加载会话

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM