Leiningen build automation toolλ︎
Leiningen will help you create, build and deploy your Clojure projects.
Practicalli recommends using Clojure CLI
For new project, Clojure CLI is recommended as it requires fewer resources and enables a more customisable approach to configuring project and running tools to support Clojure development.
Install Leiningenλ︎
Install the Leiningen tool using the specific instructions for your Operating System
{% tabs first="Linux", second="Homebrew", third="GitBash", forth="Chocolatey", fifth="Windows Manual" %}
Download the lein script to your local bin
directory. Then make the lein
script executable and run lein
to download the full version.
mkdir ~/bin
curl https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein > ~/bin/lein
chmod u+x ~/bin/lein
lein
lein
is not found, run source ~/.bashrc
to ensure your bin
directory is on the path.
If you have Homebrew installed, run the following command in a terminal window.
GitBash allows you to use the Linux lein
script, which may have less issues when installing.
Create a directory called C:\Users\your-user-name\AppData\Local\Programs\Leiningen
Download the lein
file and save it to the above directory
Open Environment variables for your account
and add the directory to your path
Open a command window and run the command: lein
The full version of Leiningen will be downloaded and Leiningen is ready to use.
If you have Chocolatey installed, add the Leiningen package by running the following command in a terminal window.
Create a directory called C:\Users\your-user-name\AppData\Local\Programs\Leiningen
Download the lein.bat
file and save it to the above directory
Open Environment variables for your account
and add the directory to your path
Open a command window and run the command: lein.bat
The full version of Leiningen will be downloaded and Leiningen is ready to use.
Run Leiningenλ︎
Check Leiningen is working by running lein
command in a terminal
If a list of Leiningen commands is shown then it is working correctly.
Create projectλ︎
Create a new Clojure project with Leiningen using the new
task
Built-in templates include app
and lib
Create a new project called playground
Open a terminal window and in a directory where you usually keep your projects, run the following command
A new directory will be created calledplayground
with a src/practicalli/playground.clj
Unit Testingλ︎
Leiningen automatically includes the test
directory when running, so no additional configuration is required if all tests reside inside the test
directory.
Run all the tests saved to file:
Run just the unit tests in a specific namepsace.
Test Pluginsλ︎
The following Leiningen plugins watch the file system and will run tests when a file change is detected in the project files.
Configure test pathsλ︎
:test-paths
added as a top level key to the defproject
configuration in the project.clj
file will configure specific paths for tests
For example, if the tests are defined under project-name/clj/tests
then the project.clj file would look as follows:
(defproject my-project "0.5.0-SNAPSHOT"
:description "A project for doing things."
:license "Creative Commons Zero"
:url "http://github.com/practicalli/my-project"
:dependencies [[org.clojure/clojure "1.10.1"]]
:test-paths ["clj/test" "src/test/clojure"]
:plugins [[lein-auto "0.1.3"]])
:source-paths
can also be used to define the location of the source code files in the same manner.