2009-10-31 21:35:25 +00:00
|
|
|
# Leiningen
|
|
|
|
|
2009-11-12 05:25:16 +00:00
|
|
|
> "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
|
2009-12-21 04:37:19 +00:00
|
|
|
> fiend from hell..."
|
2009-11-12 05:25:16 +00:00
|
|
|
> -- from Leiningen Versus the Ants by Carl Stephenson
|
2009-10-31 21:35:25 +00:00
|
|
|
|
|
|
|
Leiningen is a build tool for Clojure designed to not set your hair on fire.
|
|
|
|
|
2009-11-15 04:56:52 +00:00
|
|
|
Building Clojure projects with tools designed for Java can be an
|
|
|
|
exercise in frustration. If you use Ant, you end up copying around a
|
|
|
|
lot of the same tasks around between XML files on all your projects;
|
|
|
|
there's a lot of repetition. Maven avoids repetition, but provides
|
|
|
|
very little transparency into what's really going on behind the scenes
|
|
|
|
and forces you to become a Maven expert to script a nontrivial
|
|
|
|
build. Either way you end up writing far more XML than is necessary.
|
|
|
|
|
|
|
|
With Leiningen, your build is described using Clojure. You can put any
|
|
|
|
code you like in your project.clj file; the only requirement is that
|
|
|
|
it includes a call to defproject. You can define your own tasks in
|
|
|
|
there if you need to, but the majority of projects should be able to
|
|
|
|
get by on the tasks that are provided with Leiningen. If you do find a
|
|
|
|
common task that you need to add, you can implement it as a plugin
|
|
|
|
rather than copying and pasting among each of your projects.
|
|
|
|
|
2009-11-12 05:25:16 +00:00
|
|
|
## Installation
|
2009-11-02 07:02:16 +00:00
|
|
|
|
2010-03-13 05:04:11 +00:00
|
|
|
Leiningen bootstraps itself using the 'lein' shell script you
|
|
|
|
download, there is no separate 'install script'. It installs its
|
|
|
|
dependencies in $HOME/.m2/repository.
|
|
|
|
|
2010-01-11 17:04:32 +00:00
|
|
|
1. [Download the script](http://github.com/technomancy/leiningen/raw/stable/bin/lein).
|
2009-11-20 01:22:52 +00:00
|
|
|
2. Place it on your path and chmod it to be executable.
|
|
|
|
3. Run: <tt>lein self-install</tt>
|
2009-11-02 07:02:16 +00:00
|
|
|
|
2009-12-21 04:37:19 +00:00
|
|
|
This only works with stable versions of Leiningen; for development
|
2009-11-24 05:26:47 +00:00
|
|
|
versions see "Hacking" below.
|
|
|
|
|
2010-03-13 05:04:11 +00:00
|
|
|
On Windows you can download
|
|
|
|
[lein.bat](http://github.com/technomancy/leiningen/raw/stable/bin/lein.bat),
|
|
|
|
instead, though support on that platform is still experimental.
|
|
|
|
|
2009-10-31 21:35:25 +00:00
|
|
|
## Usage
|
|
|
|
|
2010-06-05 20:26:52 +00:00
|
|
|
$ lein new NAME # generate a new project skeleton
|
|
|
|
|
2009-10-31 21:35:25 +00:00
|
|
|
$ lein deps # install dependencies in lib/
|
|
|
|
|
2009-11-29 22:20:09 +00:00
|
|
|
$ lein test [TESTS] # run the tests in the TESTS namespaces, or all tests
|
2009-11-02 06:47:21 +00:00
|
|
|
|
2009-10-31 21:35:25 +00:00
|
|
|
$ lein repl # launch a REPL with the project classpath configured
|
|
|
|
|
2009-11-09 06:09:39 +00:00
|
|
|
$ lein clean # remove all build artifacts
|
|
|
|
|
2009-11-09 06:11:31 +00:00
|
|
|
$ lein jar # create a jar of the project
|
|
|
|
|
|
|
|
$ lein uberjar # create a standalone jar that contains all dependencies
|
|
|
|
|
2009-11-29 04:28:33 +00:00
|
|
|
$ lein install # install in local repository
|
2009-11-16 05:08:23 +00:00
|
|
|
|
2010-06-05 20:26:52 +00:00
|
|
|
These are the most commonly-used tasks; you can use "lein help" to see
|
|
|
|
a complete list. "lein help $TASK" will show the usage for a specific one.
|
2009-11-20 01:50:33 +00:00
|
|
|
|
2009-10-31 21:35:25 +00:00
|
|
|
## Configuration
|
|
|
|
|
2010-03-13 05:04:11 +00:00
|
|
|
Place a project.clj file in the project root that looks something like this:
|
2009-10-31 21:35:25 +00:00
|
|
|
|
2009-11-15 04:47:48 +00:00
|
|
|
(defproject leiningen "0.5.0-SNAPSHOT"
|
2009-11-29 22:20:09 +00:00
|
|
|
:description "A build tool designed not to set your hair on fire."
|
2009-12-02 06:28:58 +00:00
|
|
|
:url "http://github.com/technomancy/leiningen"
|
2010-06-05 20:26:52 +00:00
|
|
|
:dependencies [[org.clojure/clojure "1.1.0]
|
|
|
|
[org.clojure/clojure-contrib "1.1.0"]
|
2009-11-15 04:47:48 +00:00
|
|
|
[ant/ant-launcher "1.6.2"]
|
|
|
|
[org.apache.maven/maven-ant-tasks "2.0.10"]]
|
2010-06-05 20:26:52 +00:00
|
|
|
:dev-dependencies [[org.clojure/swank-clojure "1.2.1"]])
|
2009-11-14 22:24:36 +00:00
|
|
|
|
2010-06-05 20:26:52 +00:00
|
|
|
The "lein new" task will generate a project skeleton with an
|
|
|
|
appropriate starting point from which you can work. See the file
|
|
|
|
sample.project.clj for a detailed listing of all the configuration
|
|
|
|
options that Leiningen knows about.
|
2009-11-17 04:24:36 +00:00
|
|
|
|
2009-11-05 04:25:13 +00:00
|
|
|
## FAQ
|
|
|
|
|
2009-11-06 04:34:14 +00:00
|
|
|
**Q:** How do you pronounce Leiningen?
|
|
|
|
**A:** It's LINE-ing-en. I think.
|
2009-11-05 04:25:13 +00:00
|
|
|
|
2009-11-06 04:34:14 +00:00
|
|
|
**Q:** What does this offer over [Lancet](http://github.com/stuarthalloway/lancet)?
|
|
|
|
**A:** Lancet is more of a library than a build tool. It doesn't predefine
|
2009-11-05 04:25:13 +00:00
|
|
|
any tasks apart from what Ant itself offers, so there is nothing
|
2009-11-14 22:24:36 +00:00
|
|
|
Clojure-specific in it. Leiningen builds on Lancet, but takes
|
|
|
|
things further. In addition, it includes some Maven functionality
|
|
|
|
for dependencies.
|
2009-11-05 04:25:13 +00:00
|
|
|
|
2009-11-06 04:34:14 +00:00
|
|
|
**Q:** But Maven is terrifying!
|
|
|
|
**A:** That's not a question. Anyway, Leiningen only uses the dependency
|
2009-11-05 04:25:13 +00:00
|
|
|
resolution parts of Maven, which are quite tame. For the actual
|
|
|
|
task execution cycles it uses Ant under the covers via Lancet.
|
|
|
|
|
2009-11-06 04:34:14 +00:00
|
|
|
**Q:** But Ant is terrifying!
|
|
|
|
**A:** That's [true](http://www.defmacro.org/ramblings/lisp.html). Ant is
|
2009-11-05 04:25:13 +00:00
|
|
|
an interpreter for a [procedural language with a regrettable
|
|
|
|
syntax](http://blogs.tedneward.com/2005/08/22/When+Do+You+Use+XML+Again.aspx).
|
2009-11-24 05:26:47 +00:00
|
|
|
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.
|
2009-11-05 04:25:13 +00:00
|
|
|
|
2010-03-13 05:04:11 +00:00
|
|
|
**Q:** What's a group ID? How do snapshots work?
|
|
|
|
**A:** See the
|
|
|
|
[intro](http://github.com/technomancy/leiningen/blob/master/INTRO.md)
|
|
|
|
for background on JVM dependency concepts.
|
|
|
|
|
2009-12-21 04:37:19 +00:00
|
|
|
**Q:** What if my project depends on jars that aren't in any repository?
|
2009-12-02 06:41:04 +00:00
|
|
|
**A:** Open-source jars can be uploaded to Clojars (see "Publishing"
|
2010-06-05 20:26:52 +00:00
|
|
|
below), though be sure to use the group-id of "org.clojars.$USERNAME"
|
2009-12-02 06:28:58 +00:00
|
|
|
in order to avoid conflicts and to allow the original authors to
|
|
|
|
claim it in the future once they get around to uploading.
|
2010-06-05 20:26:52 +00:00
|
|
|
Alternatively you can do a one-off install into your local repository in
|
|
|
|
~/.m2 with Maven for Java libs or "lein install" for Clojure libs.
|
2009-12-02 06:28:58 +00:00
|
|
|
|
2010-03-13 05:04:11 +00:00
|
|
|
**Q:** What does java.lang.NoSuchMethodError: clojure.lang.RestFn.<init>(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.
|
|
|
|
|
2009-12-21 21:37:38 +00:00
|
|
|
**Q:** Is it possible to exclude indirect dependencies?
|
2010-06-05 20:26:52 +00:00
|
|
|
**A:** Yes. Some libraries, such as log4j, depend on projects that are
|
2009-12-21 21:28:19 +00:00
|
|
|
not included in public repositories and unnecessary for basic
|
|
|
|
functionality. Projects listed as :dependencies may exclude
|
2010-06-05 20:26:52 +00:00
|
|
|
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.
|
2009-12-21 21:28:19 +00:00
|
|
|
|
2009-12-21 04:37:19 +00:00
|
|
|
**Q:** How should I pick my version numbers?
|
|
|
|
**A:** Use [semantic versioning](http://semver.org).
|
|
|
|
|
2009-11-20 01:25:38 +00:00
|
|
|
## Publishing
|
|
|
|
|
|
|
|
If your project is a library and you would like others to be able to
|
|
|
|
use it as a dependency in their projects, you will need to get it into
|
|
|
|
a public repository. While it's possible to maintain your own or get
|
|
|
|
it into Maven central, the easiest way is to publish it at
|
|
|
|
[Clojars](http://clojars.org), which is a Clojure-specific repository
|
|
|
|
for open-source code. Once you have created an account there,
|
|
|
|
publishing is easy:
|
|
|
|
|
2010-06-05 20:26:52 +00:00
|
|
|
$ lein jar && lein pom
|
|
|
|
$ scp pom.xml $PROJECT.jar clojars@clojars.org:
|
2009-11-20 01:25:38 +00:00
|
|
|
|
2009-12-02 06:41:04 +00:00
|
|
|
Once that succeeds it will be available for other projects to depend
|
|
|
|
on. Leiningen adds Clojars and [the Clojure nightly build
|
|
|
|
snapshots](http://build.clojure.org) to the default repositories.
|
2009-11-20 01:25:38 +00:00
|
|
|
|
2009-11-14 23:06:21 +00:00
|
|
|
## Hacking
|
|
|
|
|
2009-11-24 06:33:31 +00:00
|
|
|
You'll need to bootstrap using a stable release before you can hack on
|
2009-11-25 02:45:49 +00:00
|
|
|
Leiningen. Grab the stable bin script (linked under "Installation"
|
|
|
|
above), put it on your $PATH as "lein-stable", and do "lein-stable
|
|
|
|
self-install". Then run "lein-stable deps" in your checkout. When that
|
|
|
|
finishes, symlink bin/lein from your checkout to your path. This will
|
|
|
|
make "lein" run from your checkout while "lein-stable" uses the jar
|
|
|
|
self-installed in ~/.m2.
|
2009-11-14 23:06:21 +00:00
|
|
|
|
2010-01-11 17:04:32 +00:00
|
|
|
The [mailing list](http://groups.google.com/group/leiningen) and the
|
2009-11-25 02:45:49 +00:00
|
|
|
leiningen or clojure channels on Freenode are the best places to
|
2009-11-29 05:35:04 +00:00
|
|
|
bring up questions or suggestions. If you're planning on adding a
|
|
|
|
feature or fixing a nontrivial bug, please discuss it first to avoid
|
2009-12-21 04:37:19 +00:00
|
|
|
duplicating effort. If you haven't discussed it on the mailing list,
|
|
|
|
please include in your pull request details of what problem your patch
|
|
|
|
intendeds to solve as well as the approach you took.
|
2009-11-20 01:22:52 +00:00
|
|
|
|
2009-11-24 05:26:47 +00:00
|
|
|
Contributions are preferred as either Github pull requests or using
|
2009-12-21 04:37:19 +00:00
|
|
|
"git format-patch" and the mailing list as is requested [for
|
|
|
|
contributing to Clojure itself](http://clojure.org/patches). Please
|
|
|
|
use standard indentation with no tabs, trailing whitespace, or lines
|
2010-06-05 20:26:52 +00:00
|
|
|
longer than 80 columns. See [this post on submitting good
|
|
|
|
patches](http://technomancy.us/135) for some tips. If you've got some
|
|
|
|
time on your hands, reading this [style
|
|
|
|
guide](http://mumble.net/~campbell/scheme/style.txt) wouldn't hurt
|
|
|
|
either.
|
2009-11-20 01:22:52 +00:00
|
|
|
|
2009-11-24 05:26:47 +00:00
|
|
|
Leiningen is extensible; you can define new tasks in plugins. Add your
|
2009-11-15 04:56:52 +00:00
|
|
|
plugin as a dev-dependency of your project, and you'll be able to call
|
2010-06-05 20:26:52 +00:00
|
|
|
"lein $YOUR_COMMAND". See the file PLUGINS.md for details.
|
2009-11-15 04:47:48 +00:00
|
|
|
|
2010-06-05 20:26:52 +00:00
|
|
|
See the [complete list of known issues](http://github.com/technomancy/leiningen/issues).
|
2010-04-17 05:24:01 +00:00
|
|
|
|
2009-10-31 21:35:25 +00:00
|
|
|
## License
|
|
|
|
|
2010-05-15 03:41:33 +00:00
|
|
|
Copyright (C) 2009-2010 Phil Hagelberg, Alex Osborne, and Dan Larkin
|
2009-10-31 21:35:25 +00:00
|
|
|
|
2009-11-06 04:36:27 +00:00
|
|
|
Thanks to Stuart Halloway for Lancet and Tim Dysinger for convincing
|
|
|
|
me that good builds are important.
|
|
|
|
|
2009-10-31 21:35:25 +00:00
|
|
|
Distributed under the Eclipse Public License, the same as Clojure
|
|
|
|
uses. See the file COPYING.
|