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).
Clojure CLI can also be used for evaluating an expressions or running Clojure from files as scripts, although these approaches are less common.
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.
The -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.
Which flag to use?
The -M
flag is used when calling a -main
function from a specified namespace. Arguments can be passed as free-form string options.
The -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-deps
and :replace-paths
values to remove project :deps
and :paths
-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
Evaluate *clojure-version*
in a REPL shows which version of the Clojure language is currently being used.
Including 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.