Leiningen is a tool for building Clojure code, downloading jars, handling java classpaths, and in general gluing all those ugly-but-necessary development details together into a coherent whole.

Leiningen runs on maven, so it is theoretically able to do anything that maven can do. In practice, Leiningen is still under development so this statement hasn’t been fully proven yet, but it should handle most small and medium-sized projects with relative ease.

Let’s walk through a typical example of managing a project with leiningen.

Creating a Project

Leiningen provides a simple way of creating a structure of a project. Let’s walk through a simple application called “fahr” that converts temperatures between Fahrenheit and Celsius.

cd ~/clj/src/
lein new fahr

That created a directory structure under the new directory ‘fahr’ that looks like this:

|-- project.clj
|-- src
| `-- fahr
| `-- core.clj
`-- test
`-- fahr
`-- test
`-- core.clj

Now let’s get in the new directory and add version control:

cd fahr
git init
git add project.clj src/fahr/core.clj test/fahr/test/core.clj
git commit

Before we can start swank, we need to edit the project.clj file to contain the line:

:dev-dependencies [[swank-clojure "1.2.1"]]

And then run:

lein deps
lein swank

Finally, we can connect to it from inside emacs by pressing:

M-x slime-connect

Happy Hacking!

Testing your code

Every time you start Leiningen, a JVM is created, Leiningen does its work, and then the JVM is destroyed. If you want to avoid this heavy startup cost, you may want to run it in interactive mode, as I do.

lein interactive

This is especially handy during development when you just type in ‘test’ repeatedly to quickly check how your code is progressing.

Distributing your code

If you want to build an ‘uberjar’, a package that contains the application and also clojure’s jar files as well, you can use the following:

cd ~/clj/src/
lein deps
lein compile
lein uberjar

When people want to run your application, now all they have to do is

java -jar fahr-standalone.jar


If leiningen was not to your liking, you may try cake, gradle, maven, or polyglot maven.