Clojure and Clojure CLIλ︎
Clojure CLI (command line interface) is the latest approach to working with Clojure projects, libraries an tools. The Clojure CLI focuses on:
- running Clojure code (applications and tools)
- starting a REPL process (Read-Eval-Print Loop) for interactive development with a Clojure editor or a command line REPL UI.
- managing dependencies (via tools.deps) and downloads from Maven and Git repositories
The Clojure CLI is extended by adding aliases for community libraries and tools, e.g. practicalli/clojure-deps-edn
Common tasks for Clojure developmentλ︎
Commands to use for common tasks and where their aliases are included in Clojure CLI tools or require an alias (either in a project or user-wide deps.edn file).
|Basic terminal UI REPL||
|Enhanced terminal UI REPL (Rebel and nREPL)||
|Create project (clojure exec)||
|Run unit tests / watch for changes||
|Run the project (clojure.main)||
|Run a function from the project (clojure.exec)||
|Find libraries (mvn & git)||
|Check for new dependency versions||
|Deploy library locally||
|Check code for unused vars||
clojure -M:lib/hotload:repl/rebel runs a rich terminal UI REPL which can use add-libs to hotload dependencies into a running REPL process.
Clojure CLI versionλ︎
clojure -Sdescribe shows the version of Clojure CLI currently installed.
-Sverbose flag shows the Clojure CLI version and basic configuration before running any task, e.g.
clojure -Sverbose -M:repl/rebel will show the Clojure CLI details and then run Rebel terminal UI.
Clojure CLI execution option flagsλ︎
The execution option flags for the
clojure command define how to run Clojure code.
||Pass alias to built-in terminal UI REPL (
||Run Clojure project with clojure.main|
||Prepare / dry run (Build scripts, CI servers, Containers)|
||Execute a fully qualified function, optional default arguments|
||Run a tool independently from a project configurations|
||Java Virtual Machine specific options (heap size, etc)|
Which flag to use?
-M flag is used when calling a
-main function from a specified namespace. Arguments can be passed as free-form string options.
-X flag is used to call a fully qualified function, which can be any function on the command line. Arguments are passed as key/value pairs and strings / collection syntax should be escaped with single quotes.
-X can use
:replace-paths values to remove project
-T flag removes project paths and deps, so is run independent of a Clojure project configuration. Tools can be installed and referred to by name, or used via an alias name and have default configuration attached.
Read the article: Clojure CLI - which execution option to use
Which version of Clojureλ︎
*clojure-version* in a REPL shows which version of the Clojure language is currently being used.
org.clojure/clojure in the project
deps.edn file allows specification of a particular version of the Clojure language. The Clojure CLI also has a default version of the Clojure dependency, which is used if no other dependency is specified.