How can I depend on each clojure contrib library?

I liked to include all clojure.contrib and require all libraries. This makes find-doc useful as a discovery tool.

Currently (clojure 1.4) clojure.contrib is split into many sub-libraries. And that pretty messes up my circuit, and that also means that I have to constantly restart the JVM every time I need a new library.

So, I am busy building a project.clj file with many lines:

[org.clojure/algo.generic "0.0.6"] .... [org.clojure/data.xml "0.0.4"] .... 

So, I can get leiningen to place each clojure contrib library in the classpath, whether I need them or not.

And I believe that it will be an impressive neck pain that with version numbers and everything.

And I wonder if anyone has a better way to do the same?

EDIT: thinking about this, if there is a webpage somewhere that has a list of library names and current versions, I can easily turn this into a project file.

+7
source share
2 answers

You can use grenade if you want to just run it in REPL (it seems that this will be the only suitable use case, right?). You can view the latest versions using the Maven Central API. I think this is better than supporting some kind of dependency project, generated or otherwise.

 (require '[cemerick.pomegranate :refer [add-dependencies]]) (add-dependencies :coordinates '[[clj-http "0.5.8"]] :repositories {"clojars" "http://clojars.org/repo"}) (require '[clj-http.client :as client]) ;; contrib project names from https://github.com/clojure (def contrib ["tools.nrepl" "tools.trace" "tools.namespace" "tools.macro" "test.generative" "math.numeric-tower" "core.match" "core.logic" "data.priority-map" "core.contracts" "tools.cli" "java.jmx" "java.jdbc" "java.classpath" "data.xml" "data.json" "core.unify" "core.incubator" "core.cache" "algo.monads" "data.generators" "core.memoize" "math.combinatorics" "java.data" "tools.logging" "data.zip" "data.csv" "algo.generic" "data.codec" "data.finger-tree"]) (defn add-contrib-dependencies "look up the latest version of every contrib project in maven central, and add them as dependencies using pomegranate." [project-names] (add-dependencies :coordinates (map (juxt (comp symbol (partial format "org.clojure/%s")) (fn [proj] (Thread/sleep 100) (-> "http://search.maven.org/solrsearch/select?q=%s&rows=1&wt=json" (format proj) (client/get {:as :json}) :body :response :docs first :latestVersion))) project-names))) 

Now you can simply call this function in the list of project names:

 user=> (add-contrib-dependencies contrib) {[org.clojure/data.zip "0.1.1"] nil, [org.clojure/java.classpath "0.2.0"] nil, [org.clojure/core.cache "0.6.2"] nil, ...} 

UPDATE: as suggested earlier, I made this answer in the library. It can be used either as nREPL middleware or manually called from the current REPL session. The code can be found at https://github.com/rplevy/contrib-repl , where you can also find instructions for use.

+8
source
+1
source

All Articles