开发者

Dynamically load dependencies in Clojure REPL

开发者 https://www.devze.com 2023-04-12 11:31 出处:网络
Is it possible to download and install previously unspecified Maven dependencies in a running Clojure REPL?

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.....


Java's default classloader behavior makes this difficult, but pomegrenade (actually, pomegranate) claims to be able to do what you want.


Alembic is a leiningen plugin that adds this functionality to the repl.

Direct quote from the README:

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.

It also adds a (load-project) function that parses the project.clj and adds missing dependencies on the fly.

0

精彩评论

暂无评论...
验证码 换一张
取 消