lein
Manage and build Clojure projects
TLDR
Generate scaffolding for a new project based on a template
Start a REPL session either with the project or standalone
Run the project's -main function with optional args
Run the project's tests
Package up the project files and all its dependencies into a jar file
SYNOPSIS
lein [global-options] <task> [task-options] [args...]
Examples:lein new app my-app
lein deps
lein test
lein run
lein repl
lein uberjar
PARAMETERS
--help
, -h
Displays general help or help for a specific task.--version
, -v
Prints the Leiningen version.--verbose
Increases verbosity of output.--silent
Suppresses most output except errors.new <template> <name>
Generates a new project from a template (e.g., app
, lib
).deps
Downloads and installs project dependencies.run [args...]
Executes the project's main function.test [namespaces...]
Runs project tests.repl
Starts a Clojure REPL (Read-Eval-Print Loop) for interactive development.jar
Creates a standalone JAR file for the project.uberjar
Packages the project and all its dependencies into a single executable JAR.install
Installs the project's JAR into the local Maven repository.clean
Removes compiled class files and other build artifacts.check
Checks the project for common errors.
DESCRIPTION
Leiningen (often just `lein`) is the most popular build automation and dependency management tool for Clojure projects. It provides a convenient way to manage the entire lifecycle of a Clojure application, from project creation to deployment. Similar to Maven for Java or npm for Node.js, Leiningen handles tasks such as fetching dependencies, running tests, compiling code, packaging applications (JARs, uberjars), and running development environments (REPLs). It simplifies the build process by allowing developers to define project settings, dependencies, and tasks in a `project.clj` file. Its plugin architecture also allows for extending its functionality, making it highly versatile for various development needs.
CAVEATS
JVM Dependency: Leiningen requires a Java Virtual Machine (JVM) to run, as it's built on Java and targets the JVM. Ensure a compatible JDK is installed and configured.
Project Configuration: The project.clj
file uses a specific EDN (Extensible Data Notation) syntax. Incorrect syntax or misconfigurations can lead to build failures.
Plugin Ecosystem: While powerful, managing and understanding the various Leiningen plugins can sometimes add complexity, especially for new users.
<I><B>`PROJECT.CLJ` FILE:</B></I>
This is the core configuration file for any Leiningen project, located in the project's root directory. It's written in Clojure syntax (EDN) and defines essential project metadata, dependencies, plugins, profiles, and tasks. It's crucial for Leiningen to understand how to build and run your project.
<I><B>PROFILES:</B></I>
Leiningen allows defining different "profiles" within project.clj
or ~/.lein/profiles.clj
. Profiles enable conditional configuration, useful for development, testing, or production environments. For example, a development profile might include specific plugins or dependencies not needed in production builds.
<I><B>PLUGINS:</B></I>
Leiningen's functionality can be extended through plugins. Plugins are themselves Leiningen projects that provide additional tasks or modify existing ones. They are declared in project.clj
and can be used to integrate with other tools, perform static analysis, deploy artifacts, and more.
HISTORY
Leiningen was created by Phil Hagelberg and first released around 2010. It quickly became the de facto standard build tool for Clojure projects due to its simplicity, extensibility, and seamless integration with the Clojure ecosystem. It abstracts away much of the complexity of classpath management and Java interoperability, making Clojure development more approachable. Its design was inspired by tools like Maven and RubyGems, aiming to provide a comprehensive solution for dependency management, testing, and deployment specific to Clojure's needs.