在 Clojure REPL 中动态加载依赖项
是否可以在运行 Clojure REPL 中下载并安装之前未指定的 Maven 依赖项?
我正在考虑一种相当常见的情况,即您想要快速暂时引入某些测试或可视化工具的依赖项,但又不想关闭当前的 REPL 会话。
例如,如果您想使用 Incanter 在当前 REPL 会话中绘制一些漂亮的数据图表,您可能会使用如下内容:
(load-dependency "incanter" "incanter" "1.3.0-SNAPSHOT")
;; now do stuff with Incanter......
大概您必须从适当的存储库触发 Maven 或 Leiningen 中的依赖关系解析/加载,但是我对它们的内部结构了解不够,不知道这在运行时是否可能......
Is it possible to download and install previously unspecified Maven dependencies in a running Clojure REPL?
I'm thinking of the fairly common case where you want to quickly pull in a dependency temporarily for some testing or visualisation tools, but don't want to close down your current REPL session.
For example if you wanted to pull in Incanter to draw some pretty charts of data in your current REPL session, you might use something like the following:
(load-dependency "incanter" "incanter" "1.3.0-SNAPSHOT")
;; now do stuff with Incanter......
Presumably you would have to trigger the dependency resoltion / loading in Maven or Leiningen from an appropriate repository but I don't know enough about their internals to know whether this is possible or not at runtime.....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Java 的默认类加载器行为使这变得很困难,但是 pomegrenade(实际上是石榴) 声称能够做你想做的事情想。
Java's default classloader behavior makes this difficult, but pomegrenade (actually, pomegranate) claims to be able to do what you want.
Alembic 是一个 leiningen 插件,它将此功能添加到 repl 中。
直接引用自述文件:
它还添加了一个
(load-project)
函数,用于解析project.clj
并动态添加缺少的依赖项。Alembic is a leiningen plugin that adds this functionality to the repl.
Direct quote from the README:
It also adds a
(load-project)
function that parses theproject.clj
and adds missing dependencies on the fly.