关于Maven:在Clojure REPL中动态加载依赖项

Dynamically load dependencies in Clojure REPL

是否可以在正在运行的Clojure REPL中下载并安装以前未指定的Maven依赖项?

我想到的是一个相当普遍的情况,您想临时为某些测试或可视化工具快速获取依赖项,但又不想关闭当前的REPL会话。

例如,如果您想使用Incanter来在当前的REPL会话中绘制一些漂亮的数据图表,则可以使用以下内容:

1
2
3
(load-dependency"incanter""incanter""1.3.0-SNAPSHOT")

;; now do stuff with Incanter......

大概您必须在适当的存储库中触发Maven或Leiningen中的依赖项解析/加载,但是我对它们的内部了解不多,无法知道在运行时是否可行.....


Alembic是一个leiningen插件,将此功能添加到了repl中。

自述文件的直接报价:

Alembic is a clojure library that allows you to distill jars onto your classpath in a running JVM instance. You can use it to add dependencies to a running REPL, either in an ad-hoc fashion, or by reloading your project.clj file.

它还添加了一个(load-project)函数,该函数解析project.clj并动态添加缺少的依赖项。


Java的默认类加载器行为使此操作变得困难,但是石榴榴弹(实际上是石榴)声称能够执行您想要的操作。