Getting Leiningen to download dependencies outside of a project
Asked Answered
B

3

7

I'm learning Clojure, but I'm not really building whole projects for each little code snippet, I just drop them into a REPL. Occasionally code snippets I'm exploring require a dependency (usually something that is/was in clojure.contrib).

The only way I know how to get those dependencies onto my computer is to have an empty leiningen project, add the dependency to project.clj and run lein deps.

Is there any way I can download libraries globally, outside of a project? If it's that I really really don't want to, why?

Brotherson answered 30/4, 2013 at 2:45 Comment(3)
1) download library jar 2) java -cp clojure.jar:some-lib-clj.jar clojure.main 3) What's so bad about having a scratch Leiningen project?Monophysite
it's not exactly what you want I think but maybe this will make it easier, github.com/mtyaka/lein-oneoffNormanormal
Seems to me that this is exactly what he wants.Monophysite
T
2

I have a small project that I use for testing code snippets and answering SO questions, and am also constantly adding dependencies. The project.clj for this project includes Pomegranate as a dependency which then makes dynamically loading other dependencies as easy as:

(use '[cemerick.pomegranate :only (add-dependencies)])
(add-dependencies :coordinates '[[my-dependency "1.2.3"]])
Timid answered 30/4, 2013 at 19:54 Comment(0)
A
2

Give lein-try a go. It's a leiningen plugin I wrote that lets you say something like lein try [my-dependency 1.0.0] or even lein try my-dependency at the command line and drop into a REPL with the dependency available.

Allurement answered 20/8, 2013 at 0:26 Comment(0)
C
1

If you are using lein-exec as your way of running one-off scripts, you can now use a little snippet at the top of the script. Add:

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

to the top of your clj. Now running lein exec [example.clj] will automatically pull down the 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 begin running lein exec on your clj files. It is a great and quick way to run code without a project.

Culbreth answered 7/10, 2014 at 13:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.