This is a study note of the Clojure CLI and tools.deps. It is based on the following resources:

After a quick try, VS Code works better with Leiningen.

1 Overview

The Clojure installation provides the clojure command and its wrapper clj. The clj provides a readline program called rlwrap that adds completion and history once the Clojure REPL is running. Clojure CLI tools provide

  • Running a REPL
  • Running Clojure programs
  • Evaluating Clojure expressions
  • Managing dependencies via tools.deps

Use clj for REPL and clojure for everythign else.

2 Basic Tasks

  • clj -Sdescribe shows the versions and configurations of the CLI tools
  • clj -Sverbose shows the version and configuration before it runs the REPL
  • Ctrl + D to exit the REPL

The most used clojure flag options are

  • -M: run with clojure.main
  • -X: execute a qualified function
  • -P: dry run (CI servers, containers)
  • -P -M:aliases: dry run main with alias deps and paths
  • -P -X:aliases: dry run function with alias deps and paths
  • -J: JVM options

Other common tasks with Practicalli Clojure deps.end:

  • Create a project using exec: clojure -X:new :template app :name practicalli/my-app
  • Create a proejct using main: clojure -M:new app practicalli/my-app
  • Download dependencies: clojure -Spath or clojure -P (plus optional aliases).
  • Run the project: clojure -M -m domain.main-namespace or clojure -X:project/run -m domain.main-namespace.
  • Find libraries from mvn and git: clojure -M:project/find-deps library-name
  • Check for new dependency versions: clojure -M:project/outdated
  • Run tests: clojure -M:test/runner
  • Package library: clojure -X:project/jars
  • Deploy library locally: clojure -X:deps mvn-install
  • Package application: clojure -X:project/uberjar

3 deps.edn

deps.edn is the configuration file using extensible data notation (edn), the language that is used to define the Clojure structure. The configuration is a map with top-level keys are :deps, :paths, :aliases and provider-specified keys for configuring dependency sources from providers such as GitHub or GitLab.

The ~/.clojure/deps.edn has global configuration and project-root/deps.edn for each project. The Clojure installation may contain deps.edn too.

Use :deps to declare dependencies. The dpendencies can be from local, git, Maven Central or Clojars.

Use :paths to define the directory for source code.