No description
Find a file
2012-05-24 09:15:53 -07:00
bin Don't break the line 2012-05-17 23:30:20 +04:00
doc Apply feedback from Steve Losh on tutorial. 2012-05-23 22:31:08 -07:00
lein-pprint Once upgraded to 1.1.1, lein2 pprint showed the output (it didn't work with the previous version - no output shown) 2012-04-08 12:57:43 +03:00
leiningen-core Merge pull request #600 from cpmcdaniel/master 2012-05-23 12:55:42 -07:00
resources Spin FAQ off into its own page. 2012-05-23 21:27:17 -07:00
src/leiningen Apologize for the slowness of Central indexes; link to web search. 2012-05-24 09:15:53 -07:00
test Fix install test. 2012-05-09 11:05:17 -07:00
test_projects Don't re-extract native deps unless deps have changed. Fixes #535. 2012-05-07 16:29:31 -07:00
.gitattributes Added .gitattributes to avoid autocrlf for bat files 2010-12-31 22:22:56 -08:00
.gitignore Ignore web directory where leiningen.org may be checked out. 2012-05-21 10:04:17 -07:00
.travis.yml Test leiningen-core in CI. 2012-02-19 16:39:14 -08:00
bash_completion.bash Improve namespace completion performance 2012-05-10 11:27:26 +02:00
COPYING Clarify license of images. 2011-07-19 19:04:15 -07:00
NEWS.md More news. 2012-05-11 16:24:31 -07:00
pcmpl-lein.el Add pcmpl-lein.el for eshell completion. 2011-01-15 10:38:41 -05:00
project.clj Bump REPL-y version for bugfixes 2012-05-21 17:48:54 -05:00
README.md Spin FAQ off into its own page. 2012-05-23 21:27:17 -07:00
sample.project.clj Spin FAQ off into its own page. 2012-05-23 21:27:17 -07:00
todo.org Allow :checksum policy to be set at the top-level of project.clj as well. 2012-05-11 11:44:43 -07:00
TUTORIAL.md fix broken link 2011-08-11 20:11:18 -05:00
zsh_completion.zsh Update news and bash/zsh completion scripts. Fixes #437. 2012-03-09 09:55:47 -08:00

Leiningen

Leiningen logo

"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 for automating Clojure projects without setting your hair on fire.

Installation

If your preferred package manager has a relatively recent version of Leiningen, try that first. Otherwise you can install by hand:

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. (I like to use ~/bin)
  3. Set it to be executable. (chmod 755 ~/bin/lein)

The link above will get you the stable release. The Leiningen 2 preview release has some great new features, but not all projects and plugins have been upgraded to work with it yet. Please see the upgrade guide for instructions on migrating to version 2.

On Windows most users can get the batch file. If you have wget.exe or curl.exe already installed and in PATH, you can just run lein self-install, otherwise get the standalone jar from the downloads page. If you have Cygwin you should be able to use the shell script above rather than the batch file.

Basic Usage

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 [TEMPLATE] NAME # generate a new project skeleton

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

$ lein repl # launch an interactive REPL session

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

$ lein install # install a project into the local repository

$ lein search [TERM] # find jars for your project.clj dependencies

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

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, search, version, and repl) may run from anywhere.

See the FAQ for more details.

Configuration

The project.clj file in the project root should look like this:

(defproject myproject "0.5.0-SNAPSHOT"
  :description "A project for doing things."
  :url "http://github.com/technomancy/myproject"
  :dependencies [[org.clojure/clojure "1.2.1"]]
  :plugins [[lein-ring "0.4.5"]])

To find specific versions of a dependency, use lein search, though note that this can be extremely slow the first time you use it.

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

Profiles

In Leiningen 2.x you can change the configuration of your project by applying various profiles. For instance, you may want to have a few extra test data directories on the classpath during development without including them in the jar, or you may want to have Swank Clojure available in every project you hack on without modifying every single project.clj you use.

By default the :dev, :user, and :default profiles are activated for each task, but the settings they provide are not propagated downstream to projects that depend upon yours. Each profile is defined as a map which gets merged into your project map. To add resources directories during development, add a :profiles key to project.clj like so:

(defproject myproject "0.5.0-SNAPSHOT"
  :description "A project for doing things."
  :dependencies [[org.clojure/clojure "1.2.1"]]
  :profiles {:dev {:resources-path ["dummy-data"]}})

You can place any arbitrary defproject entries into a given profile and they will be merged into the project map when that profile is active. In addition to project.clj, profiles specified in ~/.lein/profiles.clj will be available in all projects, though those from profiles.clj will be overridden by profiles of the same name in the project.clj file. This is why the :user profile is separate from :dev; the latter is intended to be specified in the project itself. In order to avoid collisions, the project should never define a :user profile, nor should profiles.clj define a :dev profile. If you want to access dependencies during development time for any project place them in your :user profile.

{:user {:plugins [[lein-swank "1.4.0"]
                  [lein-pprint "1.1.1"]]}}

Another use of profiles is to test against various sets of dependencies:

(defproject swank-clojure "1.5.0-SNAPSHOT"
  :description "Swank server connecting Clojure to Emacs SLIME"
  :dependencies [[org.clojure/clojure "1.2.1"]
                 [clj-stacktrace "0.2.4"]
                 [cdt "1.2.6.2"]]
  :profiles {:1.3 {:dependencies [[org.clojure/clojure "1.3.0"]]}
             :1.4 {:dependencies [[org.clojure/clojure "1.4.0-beta1"]]}})

To activate other profiles for a given run, use the with-profile higher-order task:

$ lein with-profile 1.3 test :database

Multiple profiles may be combined with commas:

$ lein with-profile qa,user test :database

Multiple profiles may be executed in series with colons:

$ lein with-profile 1.3:1.4 test :database

A single with-profile call does not apply across task comma-chains.

To see how a given profile affects your project map, use the lein-pprint plugin:

$ lein with-profile 1.4 pprint
{:compile-path "/home/phil/src/leiningen/lein-pprint/classes",
 :group "lein-pprint",
 :source-path ("/home/phil/src/leiningen/lein-pprint/src"),
 :dependencies
 ([org.clojure/tools.nrepl "0.0.5" :exclusions [org.clojure/clojure]]
  [clojure-complete "0.1.4" :exclusions [org.clojure/clojure]]
  [org.thnetos/cd-client "0.3.3" :exclusions [org.clojure/clojure]]),
 :target-path "/home/phil/src/leiningen/lein-pprint/target",
 :name "lein-pprint",
 [...]
 :description "Pretty-print a representation of the project map."}

Leiningen Plugins

Leiningen supports plugins which may contain both new tasks and hooks that modify behaivour of existing tasks. See the plugins wiki page for a full list. If a plugin is needed for successful test or build runs, (such as lein-tar) then it should be added to :plugins in project.clj, but if it's for your own convenience (such as swank-clojure) then it should be added to the :plugins list in the :user profile from ~/.lein/profiles.clj. The plugin guide explains how to write plugins.

Contributing

Please report issues on the GitHub issue tracker or the mailing list. Personal email addresses are not appropriate for bug reports. See the readme for the leiningen-core library and doc/PLUGINS.md for more details on how Leiningen's codebase is structured. Design discussions also occur in the #leiningen channel on Freenode.

Patches are preferred as GitHub pull requests, though patches from git format-patch are also welcome on the mailing list. Please use topic branches when sending pull requests rather than committing directly to master in order to minimize unnecessary merge commit clutter.

Contributors who have had a single patch accepted may request commit rights on the mailing list or in IRC. Please use your judgment regarding potentially-destabilizing work and branches. Other contributors will usually be glad to review topic branches before merging if you ask on IRC or the mailing list.

Contributors are also welcome to request a free Leiningen sticker by asking on the mailing list and mailing a self-addressed, stamped envelope.

Building

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.

For the master branch, use Leiningen 1.x to run lein install in the leiningen-core subproject directory. When the dependencies change you will also have to do rm .lein-classpath in the project root.

Once you've done that, symlink bin/lein to somewhere on your $PATH, usually as lein2 in order to keep it distinct from your existing installation.

If you want to develop on the 1.x branch, this should be unnecessary.

License

Source Copyright © 2009-2012 Phil Hagelberg, Alex Osborne, Dan Larkin, and contributors. Distributed under the Eclipse Public License, the same as Clojure uses. See the file COPYING.

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

Images Copyright © 2010 Phil Hagelberg. Distributed under the Creative Commons Attribution + ShareAlike License. Full-size version available.