
Leiningen is a project automation tool (think build tool and them some) that uses a Clojure macro to make it easy for Clojure developers to manage their project lifecycle.
A Clojure project managed by Leiningen uses a simple clojure file called project.clj
which allows developers to define a whole range of stuff about their projects. To get started you only have to define a name, a version of Clojure and any dependencies in your project.clj
and Leininge does the rest.
So lets take a quick look under the hood of Leiningen and its defproject macro to see what is going on.
The defproject macro
The defproject macro when run creates a simple map of your project to work with. Here is an example map for my project, generated by the command
lein pprint project.clj

If you add something to your project.clj
file and wonder what is has changed underneath, then looking at the project map is very useful.
Using the project map to understand what dependencies you have pulled in could be a great way to streamline your project, or help debug it if something when wrong after adding a new dependency.
Leiningen also merges your profile configuration ~/.lein/profiles.clj
along with your project.clj
settings when creating the project map. This can be seen in the above example. Near the end of the file is a :plugins keyword
, the following 3 lines are plugins I defined in my profile. Leiningen will work out the smartest way to merge your profile.clj
and project.clj
. If in doubt, you can check the project map.
The defproject macro code
Here is the source code for the defproject
macro:
1 | (defmacro defproject |
You can also see the source code of the defproject macro in context of the Leingingen project at its Github repository.
Thank you.
@jr0cket
This work is licensed under a Creative Commons Attribution 4.0 ShareAlike License, including custom images & stylesheets. Permissions beyond the scope of this license may be available at @jr0cket
