Getting Leiningen to load dependencies outside of a project

I study Clojure, but I don’t actually build entire projects for every small piece of code, I just throw them in the REPL. Sometimes the code snippets that I study require dependencies (usually what is / was in clojure.contrib).

The only way I can get these dependencies on my computer is to have an empty leiningen project, add the dependency to project.clj and run lein deps .

Is there any way to download libraries around the world, outside the project? If that's what I really don't want, why?

+4
source share
3 answers

I have a small project that I use to check for code snippets and answer questions from SO, and also constantly add dependencies. The .clj project for this project includes Pomegranate as a dependency, which then dynamically loads other dependencies as easily:

 (use '[cemerick.pomegranate :only (add-dependencies)]) (add-dependencies :coordinates '[[my-dependency "1.2.3"]]) 
+2
source

Give lein-try a go. This is the leiningen plugin I wrote that allows you to say something like lein try [my-dependency 1.0.0] or even lein try my-dependency on the command line and go into REPL with an available dependency.

+2
source

If you use lein-exec to run one-time scripts, now you can use the small snippet at the top of the script. Add:

 (use '[leiningen.exec :only (deps)]) (deps '[[clj-time "0.8.0"]]) 

at the top of your clj. lein exec [example.clj] will now automatically disable this requirement.

If you are new to lein exec, just add {:user {:plugins [[lein-exec "0.3.4"]]}} to your ~/.lein/profiles.clj and you can start running lein exec in your files clj. This is a great and quick way to run code without a project.

0
source

All Articles