Are you using a Leiningen Repository Manager?


April 12, 2012 By Tim O'Brien

Do you walk around all day wishing you could write elegant Lisp code? I know I do. When I’m in the mood for Lisp I usually go straight to Clojure, and when I’m deep in a state of Lisp-induced productivity, I’ll probably want to automate my Clojure projects with Leiningen. Leiningen is big in the clojure community with 1300 watchers and 179 forks on GitHub at the time I wrote this post. There are other clojure build tools, but there is a lot of interest in Leiningen.

Note: Mark Derricutt’s clojure-maven-plugin is also a great choice if you are looking to work with Clojure within a Maven build. We’ll write about that some other day.

Up and Running with Leiningen

The installation of Leiningen is fairly straightforward (for a developer, that is): Download this shell script, put it in ~/bin, chmod 755 the thing, and run it. The first time you run Leiningen it downloads Leiningen and creates a directory ~/.lein to store repository indexes and Leiningen distributions.

Once you’ve installed Leiningen, start the tutorial. After a few minutes, you’ll start to recognize that project.clj is really just like pom.xml without some of the insanely verbose XML you have to wade through with Maven. Like all build tools these days, it downloads artifacts from Central.

Searching Central with Leiningen

If you want to search Central, just run “lein search hibernate”. First this will download the Central index, and it isn’t lying when it tells you “this may take a while”. It may. What this is doing is downloading the repository index and storing it locally. Now there are a number of ways to search Central: Nexus and http://search.maven.org among them, but this tool does provide a convenient way to run a search at the command line.

Now, there’s one issue here. The first time your run “lein search” it takes 10-20 minutes to download the Central index. If you are not in a rush, this is a good excuse to go socialize with your co-workers and grab a cup of coffee, but if you are in a rush to find a dependency, this wait is frustrating. I have yet to find a good way to modify leiningen to search my Nexus repository by default.

For the gory details, there are a set of defaults hardcoded into project.clj here, and the last function in search.clj reads this default list. If there’s someone out there in Leiningen-land that knows of an elegant way to configure this list of default or repositories, let me know on StackOverflow . (Whomever provides an answer will famous because we’ll put your name in the yet-to-be-published Leiningen chapter of the Nexus book.)

Using Leiningen with Nexus

Chas Emerick, Michał Marczyk, and Phil Hagelberg all contributed to an overview of how to connect your Leiningen build to a repository manager. You’ll find some pointers here for omitting the default repositories from your download path and also deploying artifacts to a repository manager.

Note for Nexus users interested in using Leiningen: Clojars isn’t connected to Maven Central. If you do set up a Nexus instance, you’ll need to make sure that you add a proxy repository for http://clojars.org/repo/ and then add this to whatever Repository Group you are referencing in your project.clj. (And, I wouldn’t assume that the Clojure community would want to publish artifacts to Central, but it might make life a little easier for people setting up repository managers.)

A Leiningen Repository Manager? What?

There’s no such thing, but there’s also no such thing as a Maven repository either. No really, I stopped calling Nexus a Maven repository manager and I’ve also stopped calling Central “Maven Central”. It doesn’t make any sense to attach the format and standard of the repository to a single build tool because the concept and implementation is universal. Almost every build tool out there (even Leiningen) uses Central and calling it “Maven Central” just convinces most people that they have to use Maven to access it, and we all know that…

Maven is “Terrifying”

As an extra bonus, Leiningen has an entertaining FAQ, here’s an excerpt:

Leiningen builds on Lancet, but takes
things further. In addition, it includes some Maven functionality
for dependencies.

Q: But Maven is terrifying!

A: That’s not a question. Anyway, Leiningen only uses the dependency
resolution parts of Maven, which are quite tame. For some other
build-related functionality it uses Ant under the covers via Lancet.

I agree. Maven is terrifying. We do offer training classes to make it less terrifying.

  • cemerick

    Nice overview.  Just FYI, Leiningen v2 (preview releases out now) don’t use Lancet or Ant anymore at all, much to everyone’s benefit.