GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||
GeezerVison is showing clojure.org — Clojure - Clojure CLI Reference Clojure CLI Reference
Clojure CLI ReferenceTable of Contents
The Clojure CLI is a command-line tool to run Clojure programs on the Java Virtual Machine. The Clojure CLI uses deps.edn files to configure and download program dependencies to include on the JVM classpath. InstallationThe Clojure CLI can be installed in a variety of ways, see the installation guide for details and the release page for version information. You can also read the guide for a longer tutorial. For artifact building, check out the tools.build guide. Any version of the Clojure CLI can use any version of the Clojure language. Generally it is best to use the latest version of the CLI to have the latest features and fixes. Given a CLI version A.B.C[.D], the default version of Clojure used at the REPL will be A.B.C, however you can specify an older (or newer!) version of the language in your dependencies. UsageThe CLI is invoked via either Each execution of the Clojure CLI runs a Clojure program by determining all paths, dependencies, and main entry point, then invoking the program on the JVM. The primary kind of execution is determined by Primary commandsStart a REPL (default): Execute a function (-X): Run a tool (-T): Run a main namespace or script (-M): Option indexexec-opts: -Aaliases Apply aliases -X[aliases] Invoke function, using aliases -Ttoolname Invoke tool by local name -T[aliases] Invoke tool using aliases -M[aliases] Invoke clojure.main, using aliases -P Prepare deps but don't exec clj-opts: -Jopt Pass JVM option -Sdeps EDN Extra deps.edn data or file -Srepro Ignore user deps.edn file -Spath Compute and echo classpath -Stree Print dependency tree -Scp CP Use this classpath, ignore deps.edn -Sforce Force classpath computation -Sverbose Print path info -Sthreads Set specific number of download threads -Strace Write dep expansion trace.edn --version Print version to stdout and exit -version Print version to stderr and exit --help -h -? Print this help message Programs provided by :deps alias: -X:deps list Print deps list+licenses -X:deps tree Print deps tree -X:deps find-versions Find available lib versions -X:deps prep Prepare all unprepped libs in deps -X:deps mvn-pom Generate pom.xml for deps.edn -X:deps mvn-install Install maven jar to local repo Start a REPLUse this option to start a Clojure REPL.
To run a REPL, invoke This works in any directory, either with a deps.edn or not. If you are not in a project directory, the version of Clojure used will depend on the Clojure language version from the org.clojure dependency in the root deps.edn (will match the version number in CLI version number) or the user deps.edn in the config directory (usually not specified). To supply aliases that modify the classpath or JVM properties, use
Execute a function (-X)The Clojure CLI can execute any function on the project classpath that takes keyword args in a map as input.
Function execution ultimately needs the following pieces of information:
The function and its arguments may be supplied either via data in aliases and/or at the command line. The aliases can contain the following arg map keys:
If the function to invoke is defined in a specified alias, the function is optional on the command line. If the function symbol is specified on the command line, it overrides the The Keys on the command line may be either keywords or vector key paths (as used with Run a tool (-T)Tools are functions external to the project classpath. Running tool functions with
When constructing the classpath for the tool, the project The tool deps are included either via the tool aliases or a tool name. Tools may be installed locally with a short name for use. Installed tools can be used on any project with the same user configuration. See tool installation for more details. To run a tool by name, use Unlike Run a main namespace or script (-M)You can use the
The -M aliases (if provided) are pulled from Common uses:
Main opts can be provided in aliases with the arg map key Options-Aaliases
While -X[aliases]
The -Ttoolname, -T[aliases]
The -M[aliases]
The -P Use -Jopt Use Also see JVM opts for more information on other ways to supply JVM opts. -Sdeps deps Use -Srepro Use Clojure deps sources -Spath Use -Stree Use -Scp CP When this option is used, the classpath is not computed and the provided classpath is used instead. This is mostly useful in testing or debugging. In general, you should let the Clojure CLI compute (and cache) your classpath based on the deps.edn settings. -Sforce This flag marks the existing cached classpath (if any) to be marked as stale. The classpath will be recomputed and cache. -Sverbose Print environment and path information found and used by the Clojure CLI, mostly useful for debugging the location of various config and cache directories. This flag does not alter any other execution that may be specified on the command line, so it can be used to debug the location of the cache files for a particular command. -Sthreads N By default, dep expansion will happen using a thread pool sized based on the processor count. Use this setting to change the number of threads used during expansion. Setting to 1 will do expansion serially with a single thread. -Strace The dependency tree printed by --version, -version Prints the Clojure CLI version to either stdout ( See the tools release page for more version and changelog information. --help, -h, -? Print help to console. Also see AliasesWhen invoking commands in the context of a project, it is common to need to specify complex data that is hard to quote on the command line. As Clojure programmers, we strongly prefer to specify that data in Clojure syntax (edn). The deps.edn file format allows us to define arbitrary Clojure data and give that data a name using aliases. Aliases are simply keywords that name edn data. Each execution mode of the Clojure CLI has many configuration options (the "arg map"). These can be defined in edn maps via aliases and selected on the command line using the aliases in
When multiple aliases are supplied, the keys in the aliases arg maps are merged with the following semantics (in the order specified in the concatenated aliases):
Using aliases for custom purposesThe alias keys above are meaningful for Clojure CLI execution, but you may define aliases for any purpose. If you are creating a custom tool that needs configuration, it is a good practice to define well-known, namespaced aliases or alias-keys for use by your tool. Please refrain from adding top-level keys to the deps.edn files - they may not always be available via programmatic tools. Programs run by the Clojure CLI are given the runtime basis for the execution, including all alias data. The clojure.java.basis API added in Clojure 1.12 can be used to retrieve alias data at runtime in the program. Namespace resolutionSymbols in the exec-opts or arg maps (like
DependenciesEach dependency is defined in the deps.edn format with a lib and coordinate, multiple deps combined into a map (the alias arg map keys use the same format). deps.edn sourcesThe Clojure CLI will construct the map of paths, dependencies, and aliases to use by combining up to four deps edn sources:
The deps sources are merged into a single master deps edn in the order listed above except:
The merge is essentially ClasspathThe JVM classpath consists of a series of roots, either directory paths or paths to jar files. Classes (and Clojure files) map via package or namespace to a path relative to a classpath root. For example, the The Clojure CLI will compute a classpath based on:
Ultimately all of those combine into either:
Project pathsOnce merging of deps and alias args has occurred, there are Note that both project paths and extra-paths are resolved relative to the current directory and should refer only to paths inside the project, not parent or sibling directories. Currently, referring outside the project will emit a warning, but support for this is deprecated and will be removed in the future (use local deps instead). Dependency expansionOnce deps have been merged, there is a top-level set of dependencies and these form the roots of the dependency graph. The graph is explored top-down and each dependency is expanded in turn using the appropriate procurers (Maven. Git, local). Cycles are detected and will not be examined again. When multiple versions of the same library are found, a version selection process occurs. The dependency expansion page has more details on this process but generally the newest version of a library is used. The top-level dependency versions however, are always used without modification - if you need to specify a specific version or resolve a conflict, set the version in a top-level dependency. Dependencies are ordered in graph depth from the top, and alphabetically sorted by lib name at each level. For more information on the arg map modifiers like Classpath constructionThe classpath will contain:
Classpaths may further be modified by the arg map key You can print the computed classpath with -Spath. JVM propertiesJVM properties have several sources:
All JVM command-line options are concatenated in the order above. In most cases, JVM options later on the command-line will override any previous setting, but in all cases the semantics of the concatenated options are those of the JVM. There is no de-duplication or replacement of options. CLI commandThe
Step 2 is done with an uberjar that is part of the Clojure CLI installation - generally you do not control the classpath or configuration of that JVM (but see environment variables for some exceptions). JavaYou are expected to install Java and have it available by one of several means when using the Clojure CLI. Java 8 or higher is required. Any Java distribution will work. Java is found by checking the following in this order:
If not found, the CLI will stop with an error message. If Directories and cachingThere are several important directories used by the Clojure CLI, this section details how they are computed. Project directoryThe project directory is the current directory. If the project directory contains a deps.edn file, that will be used as the project deps source. There is no option for executing in the context of a remote project directory. Config directoryThe config directory contains:
The config directory is computed as follows:
If the config directory does not exist, it will be created and the following files will be copied to it:
Cache directoryEvery execution of the CLI uses a cache directory to store computed classpath and other files. The cache directory is computed as follows:
The files in the cache directory are a cache to improve startup time when using a classpath that has already been computed. In general, this cache should never be stale, however you can use When you install a new version of the CLI, this sometimes invalidates the cache (if the cache key format has changed), causing commands you have run before to recompute the classpath. The Clojure CLI never deletes files in the cache directories, so it is up to you if you wish to clean these directories periodically. It is a good practice to include Environment varsThe following environment variables can influence CLI execution (many are described in more detail elsewhere on this page):
Keys and key pathsWith the -X or -T exec-opts you can supply key-path/value pairs on the command line. The key-path is either a single key or a vector of keys to refer to a nested key (as with
In addition to passing key-path/value pairs and key paths in the command line, an optional map providing value mappings may be passed as the final argument. This map will merge with and perhaps override the previously provided key-path/value mappings:
Quoting keys and valuesKeys and values on the command line are read as edn. The following data can be used without quoting:
These data types need to be surrounded by single quotes:
On Windows, WSL2 shells can follow the advice above, but using clojure.exe, additional escape quoting is required for string values. Unfortunately the combination of quoting rules for converting command line Windows program arguments, quoting, and word splitting are very complicated. To pass a string value at the top level, if the string value does not have spaces, you can use
For string values nested inside other collections, use double quotes if there are spaces and triple quotes if there are not:
ProgramsThe Clojure CLI is designed to provide access to programs (functions) in other libraries with their own independent classpath. This capability is leveraged to provide expanded functionality via the built-in Dependency list
Prints sorted list of all transitive dependencies selected for the classpath, and license information (if found). Additional options can be used to select aliases or other classpath modifications, or to modify printing information. See API docs. Dependency tree
Prints dependency tree with inclusion/exclusion information as determined during dependency expansion). Additional options can be used to select aliases or other classpath modifications, or to modify printing information. For example, the following can be used to print the deps tree for a
See API docs. Alias list
This program prints all aliases available at the command line based on the current deps environment. Additional options can be used to select aliases or other classpath modifications. See API docs. Help functionsThe
Example for listing the set of functions in the
Example for listing the set of functions in an alias:
Print the docstrings for the help namespace itself (note that
See: API docs Prep libsSource libs with Clojure source can immediately be added to the classpath of a project using it. However, some source libs require some preparation before they can be added, for example due to needing Java compilation, or copying / replacing resource files, etc. The Clojure CLI will now detect projects that need preparation and prevent the program from being run from source unless the prep step has been completed. If your library needs preparation, add the
The keys under
Thus, the deps.edn should also have an alias that can execute the fn specified. See the tools.build Guide for how to use tools.build to define a build script with an invokable function. If you add this git library as a dependency and try to run a program, the Clojure CLI will download it, detect that it needs preparation, and that it has not been prepared ("target/classes" path does not exist), and exit. To find and "prepare" libs in the dependency tree you can use the
The prep task will find all libs in the dependency expansion and look for libs that are source libs, need prep (based on their Once a library has been prepped, it does not need to be prepped again by other users of this git library version.
See: API doc Find versionsTo search for available versions of a Maven or git lib use the
The params that can be provided are:
See: API doc Local Maven installThe The install params include the following options:
You can pass overrides on the command line for these as needed:
As mentioned above, edn strings must be in double quotes, and then single-quoted for the shell. A pom file must be either provided explicitly, generated from :lib/:version, or found inside the .jar file (the default). See: API doc Generate Maven pomUse the following program to generate or update an existing pom.xml with the deps and paths from your project:
See: API doc ToolsA tool is a collection of functions delivered in a lib. Tool functions are run in a separate process with their own classpath, independent of the project classpath. Tool functions take a single map argument and are invoked with -T (same key value arg syntax as -X style execution). Tools are described either via an alias (which can be shared by others using the project), or by a local tool name installed on your machine (which can be shared across projects). Tool installationA tool for managing tools is automatically installed by the Clojure CLI under the name "tools". There are several useful functions provided:
InstallWhen you’ve determined which version of a tool to install, use the
The args to
For example:
On Windows, additional escape quoting is required:
Note that git deps can be fully described at tool installation time with only a git lib name (used to form a git url by convention), and a git tag. Alternately, the coord may contain an explicit Best practices for tool authorsBest practices:
Tools can provide these instructions for users:
Function execution protocolSome tools provide functions designed to be used for programmatic execution from another process, with the following constraints and expectations:
There are several argument map keys that have special significance to the Clojure CLI during -X or -T. All of these keys will be removed from the argument map before the function is invoked:
The result is wrapped into a printed envelope map with the following keys and returned via the CLI stdout:
A consumer API for this protocol is provided since Clojure 1.12.0-alpha2. ProcurersDependency coordinates are interpreted by procurers, which understand a particular coordinate type and know how to find dependencies and download artifacts for a library. The Clojure CLI currently suports the folllowing procurers: Maven, Git, and local (which includes both directories and jars). The underlying tools.deps library supports procurer extensions when used as a library. The coordinate attributes determine which procurer is used. In general, most procurer attributes are qualified per procurer type (there are a few exceptions). Procurer-independent coordinate attributes use the Some procurers may also look for configuration attributes at the root of the deps.edn configuration map using the the same qualifier. MavenThe Maven procurer uses the qualifier See the deps.edn reference for details on the Maven coordinate type and Maven procurer config. Maven authenticated reposFor Maven deps in authenticated repositories, existing Maven infrastructure is used to convey credentials. In your
Then in your
Then just refer to your dependencies as usual in the Maven S3 reposThe Add a
S3 buckets are specific to the AWS region they were created in. The s3 transporter will attempt to determine the bucket’s location. If that doesn’t work, you can specify the bucket region in the url explicitly: For authenticated repos, AWS credentials can be set in the
AWS S3 credentials can be set in the environment using one of these mechanisms:
For more information, most of the advice in this AWS document describes how credentials are located. Note however that the Java system properties options will NOT work with the Clojure CLI (but would work if using the tools.deps library directly). Maven proxiesIn environments where the internet is accessed via a proxy, existing Maven configuration in
Refer to the Maven Guide to using proxies for further details. Maven HTTP headersFor adding custom headers to outgoing HTTP requests, existing Maven configuration in
The server id in
This mechanism is used by repositories that authenticate using a token, rather than by username and password. GitThe See the deps.edn reference for details on the Git coordinate type. Configuration and debuggingThe The following environment variables can be set to control git usage:
LocalThe GlossaryLibrary A collection of Clojure or other code that solves some problem, managed under a single directory root. In typical (but not exclusive) usage, most GitHub repos hold a single library. Each library has a distinct namespaced name - in Maven this is determined by the group-id/artifact-id. Artifact A library released in a container file, capturing the state of the library at a point in time, possibly subjected to some build process, labeled with a version, containing some manifest documenting its dependencies, and packaged in e.g. a jar. Coordinate A particular version of a library chosen for use, with information sufficient to obtain and use the library. Dependency An expression, at the project/library level, that the declaring library needs the declared library in order to provide some of its functions. Must at least specify library name, might also specify version and other attrs. Actual (functional) dependencies are more fine-grained. Dependency types:
Classpath (and roots/paths) An ordered list of local 'places' (filesystem directories and/or jars) that will form the root paths for searches of requires/imports at runtime, supplied as an argument to Java which controls the semantics. We discourage order-dependence in the classpath, which implies a namespace or resource file is duplicated (and thus likely broken). Expansion Given a set of root dependencies, a full closure of the transitive dependency set. Resolution Given a collection of root dependencies and additional modifications, creates a fully-expanded dependency tree, then produces a mapping from each library mentioned to a single version to be used that would satisfy all dependents, as well as the local path to that source or artifact. We will also include those dependents for each entry. Conflicts arise only if libraries depend on different major versions of a library. Version A human numbering system whose interpretation is determined by convention, often x.y.z. One popular scheme is "semantic versioning" aka "semver", which ascribes meaning to changes at each level, e.g. a change in the first major number indicates breaking change. Version difference This occurs when the dependency expansion contains the same library with more than one "version" specified but where there is a relative ordering (either by number or by sha etc). Version differences can be resolved by choosing the "later" or "newest" version when that relationship can be established. Version conflict A version conflict occurs when the dependency expansion contains the same library with more than one "version" such that the best choice cannot be automatically chosen:
Maven Repo A repository of library artifacts - e.g. Maven central or Clojars Copyright 2008-2022 Rich Hickey | Privacy Policy
Logo & site design by Tom Hickey Published 2026-11-11
Update this page | ||
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |