Fetching contributors…
Cannot retrieve contributors at this time
243 lines (184 sloc) 10.4 KB


"Leiningen!" he shouted. "You're insane! They're not creatures you can fight--they're an elemental--an 'act of God!' Ten miles long, two miles wide--ants, nothing but ants! And every single one of them a fiend from hell..." -- from Leiningen Versus the Ants by Carl Stephenson

Leiningen is a build tool for Clojure designed to not set your hair on fire.

Leiningen logo

Building Clojure projects with tools designed for Java can be an exercise in frustration. With Leiningen, you describe your build with Clojure.


Leiningen bootstraps itself using the lein shell script; there is no separate 'install script'. It installs its dependencies upon the first run on unix, so the first run will take longer.

  1. Download the script.
  2. Place it on your path and chmod it to be executable.

To track development of Leiningen you may use the master version of the script instead. See the "Building" section below.

On Windows most users can

  1. Download the Windows distribution
  2. Unzip in a folder of choice.
  3. Include the "lein" directory in PATH.

If you have wget.exe or curl.exe already installed and in PATH, you can download either the stable version lein.bat, or the development version and use self-install.


The tutorial has a detailed walk-through of the steps involved in creating a new project, but here are the commonly-used tasks:

$ lein new NAME # generate a new project skeleton

$ lein deps # install dependencies in lib/

$ lein test [TESTS] # run the tests in the TESTS namespaces, or all tests

$ lein repl # launch an interactive REPL session and socket server

$ lein jar # package up the whole project as a .jar file

$ lein install [NAME VERSION] # install a project

Use lein help to see a complete list. lein help $TASK shows the usage for a specific one.

You can also chain tasks together in a single command by using commas:

$ lein clean, test foo.test-core, jar

Most tasks need to be run from somewhere inside a project directory to work, but some (new, help, version, plugin, and the two-argument version of install) may run from anywhere.

The install task places shell scripts in the ~/.lein/bin directory for projects that include them, so if you want to take advantage of this, you should put it on your $PATH.


Place a project.clj file in the project root like this:

(defproject leiningen "0.5.0-SNAPSHOT"
  :description "A build tool designed to not set your hair on fire."
  :url ""
  :dependencies [[org.clojure/clojure "1.1.0"]
                 [org.clojure/clojure-contrib "1.1.0"]]
  :dev-dependencies [[swank-clojure "1.2.1"]])

The lein new task generates a project skeleton with an appropriate starting point from which you can work. See the sample.project.clj file for a detailed listing of configuration options.

You can also have user-level configuration that applies for all projects. The ~/.lein/init.clj file will be loaded every time Leiningen launches; any arbitrary code may go there.

You can also manage your plugins with the plugin task. Use the same arguments you would put in the Leiningen :dev-dependencies if you were only using the plugin on a single project.

$ lein plugin install lein-clojars/lein-clojars "0.6.0"

See the plugin task's help for more information.

$ lein plugin help


Q: How do you pronounce Leiningen?
A: It's LINE-ing-en. I think.

Q: What does this offer over Lancet?
A: Lancet is more of a library than a build tool. It doesn't predefine any tasks apart from what Ant itself offers, so there is nothing Clojure-specific in it. 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 the actual task execution cycles it uses Ant under the covers via Lancet.

Q: But Ant is terrifying!
A: That's true. Ant is an interpreter for a procedural language with a regrettable syntax. But if you treat it as a standard library of build-related functions and are able to write it with a more pleasing syntax, it's not bad.

Q: What's a group ID? How do snapshots work?
A: See the tutorial for background.

Q: How should I pick my version numbers?
A: Use semantic versioning.

Q: What if my project depends on jars that aren't in any repository?
A: Open-source jars can be uploaded to Clojars (see "Publishing" in the tutorial), though be sure to use the group-id of "org.clojars.$USERNAME" in order to avoid conflicts and to allow the original authors to claim it in the future once they get around to uploading. Alternatively you can do a one-off install into your local repository in ~/.m2 with Maven. Add a dependency to project.clj that doesn't exist in any remote repository and run lein deps. It won't succeed, but the output will include the mvn invocation to do this. It's much better to get the dependency in a remote repository for repeatability reasons though. For teams working on private projects Hudson works well.

Q: How do I write my own tasks?
A: If it's a task that may be useful to more than just your project, you should make it into a plugin. You can also include one-off tasks in your src/leiningen/ directory if they're not worth spinning off; the plugin guide shows how.

Q: I want to hack two projects in parallel, but it's annoying to switch between them.
A: Use a feature called checkout dependencies. If you create a directory called checkouts in your project root and symlink some other projects into it, Leiningen will allow you to hack on them in parallel. That means changes in the dependency will be visible in the main project without having to go through the whole install/switch-projects/deps/restart-swank cycle.

Q: Is it possible to exclude indirect dependencies?
A: Yes. Some libraries, such as log4j, depend on projects that are not included in public repositories and unnecessary for basic functionality. Projects listed as :dependencies may exclude any of their dependencies by using the :exclusions key. See sample.project.clj for details.

Q: It says a required artifact is missing for "super-pom". What's that?
A: The Maven API that Leiningen uses refers to your project as "super-pom". It's just a quirk of the API. It probably means there is a typo in your :dependency declaration in project.clj.

Q: What does java.lang.NoSuchMethodError: clojure.lang.RestFn.(I)V mean?
A: It means you have some code that was AOT (ahead-of-time) compiled with a different version of Clojure than the one you're currently using. If it persists after running lein clean then it is a problem with your dependencies. If you depend on contrib, make sure the contrib version matches the Clojure version. Also note for your own project that AOT compilation in Clojure is much less important than it is in other languages. There are a few language-level features that must be AOT-compiled to work, generally for Java interop. If you are not using any of these features, you should not AOT-compile your project if other projects may depend upon it.

Q: What can be done to speed up launch?
A: The "server" Hotspot compiler in the JVM is optimized for long-running processes and has quite a poor startup time. Leiningen will try to launch a client JVM, but this only works on 32-bit JVM installations. If you are on a 64-bit machine you can still use a client JVM; on Ubuntu use the ia32-sun-java6-bin package. Once you've installed it, set the JAVA_CMD environment variable to /usr/lib/jvm/ia32-java-6-sun/bin/java. Using the interactive command, the swank-clojure plugin, and the socket started by the repl command are also good ways to avoid paying the startup time penalty.


Please report issues on the Github issue tracker or the mailing list. Personal email addresses are not appropriate for bug reports. See the file for more details on how Leiningen's codebase is structured.


You don't need to "build" Leiningen per se, but when you're using a checkout you will need to get its dependencies in place. If you have a copy of an older Leiningen version around (installed as lein-stable, for example), then you can run "lein-stable deps" in your checkout.

Alternatively a lein self-install will usually get you what you need. However, this will occasionally fail for very new SNAPSHOT versions since the standalone jar will not have been uploaded yet.

You can also use Maven, just for variety's sake:

$ mvn dependency:copy-dependencies
$ mv target/dependency lib

See the file for instructions on contributing.


Copyright (C) 2009-2010 Phil Hagelberg, Alex Osborne, Dan Larkin, and contributors.

Thanks to Stuart Halloway for Lancet and Tim Dysinger for convincing me that good builds are important.

Distributed under the Eclipse Public License, the same as Clojure uses. See the file COPYING.