I'm relatively new to Clojure and Java. Why is the lib folder in a lein project not added to the git repo of a lein project? I would think it that would be convenient to have all the necessary jars there for distributed development.
4 Answers
In a Leiningen project, the project.clj file dictates the project's dependencies, and when you run 'lein deps', all dependencies listed in the project.clj file are downloaded to lib/. Therefore, there's no need to check in the jars because the project.clj in combination with the 'lein deps' command is all that's necessary for another person to reproduce the same lib/ that you have. Checking in all the jars is redundant and a waste of space.
Moreover, as mblinn points out, it's better to pull jars from artifact repositories designed for the purpose of distributing and updating dependencies, rather than constantly changing and committing new jars whenever a dependency gets updated. This is especially true when your project depends on snapshot jars, which are subject to frequent change; if you checked in the jars, you'd have to check in a new jar every time the snapshot gets updated, but if you rely on 'lein deps' to pull jars from artifact repos, then you'll stay up to date with no effort. But even for non-snapshot jars, updating a dependency by changing its version in project.clj and then running 'lein deps' is a lot easier and faster than manually placing the jar in lib/ and checking it in.
I hope the above explanation was accessible. If not, and you don't understand some of the concepts discussed, like artifact repositories or dependencies, let me know and I'll explain.

- 1,236
- 13
- 15
-
I put [rome/rome "1.0"] in my project :dependencies, but when I try lein deps, I get an error saying I need to download the rome:rome.jar:1.0 manually. At this point I don't know what to do. – dan Feb 18 '11 at 05:31
-
either upload rome to clojars or to your local maven repo then lein will find it – Hamza Yerlikaya Feb 18 '11 at 11:42
-
Leiningen downloads jars from a few default repositories, most prominently central (as in Maven central) and clojars; you can find the full list here: http://stackoverflow.com/questions/4615592/what-are-the-leiningen-default-repositories Regarding the specific problem of [rome/rome "1.0"], it looks like the 1.0 release of Rome has not been put in the central repository (see http://mvnrepository.com/artifact/rome/rome and http://repo2.maven.org/maven2/rome/rome/, hence the inability to get it using 'lein deps'. – clizzin Feb 18 '11 at 21:39
-
At this point, shit becomes kind of annoying. The easiest solution, as @hamza-yerlikaya points out, is to place the jar in your local Maven repo, i.e. at ~/.m2/repository/rome/rome/1.0/rome-1.0.jar. – clizzin Feb 18 '11 at 21:39
-
The harder solution is to make sure Rome 1.0 is available in a remote repository like central or clojars, but pushing a jar out requires generating a pom.xml file, which if you're lucky is included in the release, but if you're not is a bitch because you'll have to write it yourself. In your case, Rome has had pre-1.0 releases pushed to central, so I bet it includes a pom.xml file that you'll just have to update to ensure that its version number is 1.0 instead of 0.9 or something earlier. Instructions for pushing to clojars can be found at: https://github.com/ato/clojars-web/wiki/Pushing. – clizzin Feb 18 '11 at 21:39
-
I'm not sure about instructions for pushing to central, but maybe this is helpful: http://maven.apache.org/guides/mini/guide-central-repository-upload.html In any case, this is an edge case: I almost never touch Maven; Leiningen handles everything for me. About the only thing you need to know when dealing with Java dependencies is how to to translate POM XML into a Leiningen project.clj-style description, e.g., the two snippets shown at http://clojars.org/feedme -- oh hey, look a Clojure project based on Rome! Maybe you can use that. ;) – clizzin Feb 18 '11 at 21:40
-
By the way, apologies for the multiple comments and lack of separation into paragraphs. Stack Overflow has profoundly irritating limitations on length and formatting in comments. – clizzin Feb 18 '11 at 21:42
-
Oh, I found some more information about how to use the mvn command to install a jar to your local ~/.m2 repository: http://stackoverflow.com/questions/442230/how-to-manually-install-an-artifact-in-maven-2/442243#442243 Hope that helps! – clizzin Feb 18 '11 at 21:44
Git is astonishingly bad at storing binary files. If you check in your jars and then have to perform upgrades down the line, soon your repository will be hundreds of megabytes.
One of the biggest advantage of automatic dependency management is that your libraries are not stored in your VCS, along with all its subtle implications when it comes to versioning.
As leiningen internally uses maven artifact resolution, you need to manually specify which artifact repositories in case the required dependency is not found in the default repository, namely maven central repository, clojure releases and clojars
E.g. in case of rome v1.0 which is not yet deployed on maven central but it's found on java.net project kenai repo you'll have to type in your project.clj something along these lines:
...
:dependencies [[rome/rome "1.0"] ...]
:repositories {"kenai" "http://download.java.net/maven/2/"}
...

- 13,414
- 1
- 48
- 67
Well the whole point of Leiningen or any other dependency management tool is that it manages your dependencies for you. Those dependencies are located in separate artifact repositories that are better suited to dealing with public releases of software artifacts than source control systems are. Leiningen piggybacks off Maven's (a populate java build/dependency management tool) repository system; however, there are Clojure-specific artifact repos as well.
Anyhow, the whole point is that you declare the dependencies that your project has in your project.clj, and check that project.clj file into source control. Other developers check it out and run 'lein deps' to pull those dependencies down, and voila!