LinuxCommandLibrary

clojure

Run Clojure programs

TLDR

View documentation for the original command

$ tldr clj
copy

SYNOPSIS

clojure [options] [main-fn] [args...]
clojure -M [options] [main-fn] [args...]
clojure -P [options]
clojure -S<mode> [options]
clojure -T<tool> [tool-args...]

PARAMETERS

-Sdeps <EDN>
    Specifies additional dependency information in EDN format, merged with existing deps.edn content.

-Spath
    Prints the calculated effective classpath to standard output and exits.

-Sforce
    Forces recomputation of the classpath, bypassing cached versions.

-Scp <path>
    Explicitly sets the classpath instead of calculating it from deps.edn.

-J<jvm-opt>
    Passes a raw JVM option directly to the Java Virtual Machine (e.g., -J-Xmx2g).

-A<alias>
    Applies one or more aliases defined in deps.edn (comma-separated for multiple).

-M
    Invokes the main execution mode, typically used to run an application's main function via its :main-opts or :main-class.

-m <main-fn>
    Specifies the main function to run from the current classpath (used with -M or implicitly for scripts).

-r or --repl
    Starts a Clojure REPL (Read-Eval-Print Loop) for interactive development.

-e <form>
    Evaluates a Clojure form string passed as an argument, then exits.

-T<tool>
    Invokes a specific tool defined via a :tool alias in deps.edn.

-P
    Prints project information, including effective aliases, paths, and dependencies.

--version
    Prints the Clojure CLI version and exits.

DESCRIPTION

The clojure command (often invoked as clj) is the official command-line interface for running Clojure programs and interacting with the Clojure runtime. It leverages Clojure's tools.deps.alpha library for dependency management and project configuration, typically defined in deps.edn files.

Unlike traditional language runtimes that might only execute a single script, clojure is designed to orchestrate complex projects, managing classpaths, JVM options, and different execution modes (like running a main function, starting a REPL, or executing specific tools). It acts as a wrapper around the Java Virtual Machine (JVM), setting up the necessary environment for Clojure code execution. Its primary uses include starting a Read-Eval-Print Loop (REPL) for interactive development, executing a Clojure application's main entry point, or running custom build and development tools.

CAVEATS

The clojure command requires a Java Development Kit (JDK) or Java Runtime Environment (JRE) to be installed and accessible on the system's PATH. It is not a standard Linux utility and must be installed separately, usually through a package manager or by downloading the official clojure CLI script. Its behavior heavily depends on the presence and content of deps.edn configuration files in the current directory or its parent directories, which define dependencies, source paths, and aliases. The command is primarily designed for Clojure projects and is not applicable for general system administration.

<I>DEPS.EDN</I> INTEGRATION

The clojure command's core functionality is deeply intertwined with the deps.edn file. This file, typically located at the root of a Clojure project, is an EDN-formatted configuration that defines project dependencies, source code paths, test paths, and custom aliases. The CLI parses this file to construct the Java classpath, resolve dependencies, and apply specific configurations (like adding development tools or custom main functions) based on the supplied command-line options and aliases.

INTERACTIVE REPL USAGE

One of the most common uses of the clojure command is to launch a Read-Eval-Print Loop (REPL). By running clojure -A:dev -r (where :dev is a common alias for development dependencies and REPL setup), developers gain an interactive environment to evaluate Clojure code, experiment with libraries, and connect to running applications for live debugging and development. The REPL is a cornerstone of Clojure's iterative and exploratory development workflow.

HISTORY

The clojure command-line interface (CLI) is a relatively modern addition to the Clojure ecosystem, officially introduced around 2018. Before its advent, Leiningen and Boot were the predominant build and project management tools for Clojure. The clojure CLI, built around the tools.deps.alpha library, was developed to provide a simpler, more direct, and arguably more flexible approach to dependency management and project execution, leveraging plain EDN (Extensible Data Notation) for configuration instead of DSLs or build files. It aims to integrate more seamlessly with the underlying Java ecosystem and offers a powerful aliasing system for custom workflows. Its evolution reflects a desire for a 'native' CLI experience, optimized for Clojure's specific needs, and has become the de facto standard for new Clojure projects.

SEE ALSO

java(1), lein(1), boot(1)

Copied to clipboard