How to install a dependency in a Clojure project
Asked Answered
G

2

13

This is a noob question, so I'm sorry if I offend somebody.

But how do I install seesaw on a *nix computer? Yes, I've read the README.MD file, but how does the project.clj know where to find the library jars (for seesaw for example)?

Gorlin answered 15/10, 2012 at 22:19 Comment(0)
I
17

Edit project.clj and add the dependency (the vector of project-identifying info and version) to the :dependencies vector in project.clj.

The dependency declaration looks like this: [seesaw "1.4.2"] Which you find by searching for seesaw on http://clojars.org.

Your project file should at minimum look something like:


(defproject my-awesome-gui-application "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :dependencies [[org.clojure/clojure "1.4.0"]
                 [seesaw "1.4.2"]])

If you are using a newer version of leiningen you can type lein deps :tree to see your dependency tree. In other words you can see what libraries are actually being used, ie. the ones you declared and their transitive dependencies.


$ lein deps :tree
 [org.clojure/clojure "1.4.0"]
 [seesaw "1.4.2"]
   [com.jgoodies/forms "1.2.1"]
   [com.miglayout/miglayout "3.7.4"]
   [j18n "1.0.1"]
   [org.fife.ui/rsyntaxtextarea "2.0.3"]
   [org.swinglabs.swingx/swingx-core "1.6.3"]
     [org.swinglabs.swingx/swingx-action "1.6.3"]
     [org.swinglabs.swingx/swingx-autocomplete "1.6.3"]
       [org.swinglabs.swingx/swingx-common "1.6.3"]
     [org.swinglabs.swingx/swingx-painters "1.6.3"]
     [org.swinglabs.swingx/swingx-plaf "1.6.3"]

If you are using an older version of leiningen, type lein deps and look in ./libs to see what jars got fetched (newer versions of lein are smarter and use the jars in ~/.m2 directly instead of copying them into your project. The directory ~/.m2 is the location of your local Maven repository. Leiningen deals with Maven and downloads all the dependencies you've specified so that you don't have to worry about Maven directly.)

I mentioned Maven and your local maven repository in ~/.m2. With any luck you may never have to think about Maven at all (except perhaps browsing through maven central to look up Java libs to stick in your project.clj), but there are times when you might suspect that a jar was corrupted or something to that effect, and it is good to know that you can just blow away that state by deleting your .m2 repository.

Impeccable answered 15/10, 2012 at 23:37 Comment(0)
M
7

project.clj files specify the project configuration for leiningen.

Leiningen downloads and installs the dependencies specifies in the project.clj file and starts the project / runs the repl process / compiles the project to a java jar / whatever. See the link above. In short, leiningen is the most popular glue between your basic OS and the basic java-based clojure runtime/compiler.

Normally, you should not have to install any clojure libs (or even clojure). Except when you need additional libs to develop/debug the current project (and often you don't), you just install leiningen, and leiningen will install the dependencies for the project you want to run.

To be more specific: leiningen gets its download locations/install instructions by delegating to maven, which is a very interesting project. But possibly not worth looking into too closely if your time is precious.

Masochism answered 15/10, 2012 at 22:27 Comment(1)
I like this explanation. It clarified a lot of doubts I had about leiningen.Gorlin

© 2022 - 2024 — McMap. All rights reserved.