# Clojure deps.edn Repositories

> Use a CloudRepo Maven repository from the Clojure CLI and deps.edn: the repository entry, the settings.xml credential, deps-deploy, and what fails.

The Clojure CLI (tools.deps) reads dependencies from Maven repositories, and a CloudRepo Maven repository is one. There is no separate deps.edn repository type. You need the repository URL in `deps.edn`, a credential in `~/.m2/settings.xml`, and, to publish, deps-deploy.

## Before you start

- A Maven repository to read from and publish to. [Creating a Repository](/docs/manage/repositories.html#creating-a-repository) explains how to make one.
- A repository token that covers it. Choose **Download and publish packages** when you publish. The token page, [Repository Tokens](/docs/authenticate/repository-tokens.html), shows how to mint one. In the `settings.xml` below, the `<username>` is the email address that owns the token and the `<password>` is the token.
- The repository address, `https://your-org.mycloudrepo.io/repositories/your-repo`. Its [Connection Settings](/docs/manage/repositories.html#view-connection-settings) page displays the same address with your organization and repository already filled in.
- The Clojure CLI and, to publish, deps-deploy. The output quoted on this page comes from Clojure CLI 1.12.4.1602 and deps-deploy 0.2.5.

> **Note:** The Clojure CLI uses a repository token, not your admin portal password.

## Connect the Clojure CLI

**deps.edn**

**1. Put the credential in `~/.m2/settings.xml`.** tools.deps looks for a `<server>` whose `<id>` is the name of the repository in `deps.edn`. `${env.CLOUDREPO_TOKEN}` is filled in from an environment variable when the CLI runs, so the file never holds the token:

`~/.m2/settings.xml`

```xml
<settings>
  <servers>
    <server>
      <id>cloudrepo</id>
      <username>you@example.com</username>
      <password>${env.CLOUDREPO_TOKEN}</password>
    </server>
  </servers>
</settings>
```

**2. Name the repository in `deps.edn`.** The key, `"cloudrepo"`, must be the `<id>` from step 1. The Clojure CLI accepts `https://` repository URLs only:

`deps.edn`

```clojure
:mvn/repos {"cloudrepo" {:url "https://your-org.mycloudrepo.io/repositories/your-repo"}}
```

**3. Resolve.** Add a dependency published to the repository, then run this in the same directory as `deps.edn`. It downloads the dependencies and anything they need, then stops:

**Terminal**

```bash
clojure -P
```

Expected: the command ends with no error. The Clojure CLI sends no credential on its first request. CloudRepo replies with `401` and a `WWW-Authenticate: Basic` header, and the CLI retries with your email and token. If a request trace shows a `401` before each download, that is this auth challenge, not an error.

## Publish with deps-deploy

tools.deps resolves; it does not publish. [deps-deploy](https://github.com/slipset/deps-deploy) uploads a jar and its `pom.xml` to a Maven repository. Build the jar and the pom with tools.build (see its [guide](https://clojure.org/guides/tools_build)), then add an alias to `deps.edn`. The guide’s build writes the pom inside its class directory, and deps-deploy looks for `pom.xml` in the directory you run it from, so the alias names the pom with `:pom-file`. The repository is a **map**, and the credential comes from two environment variables, not from `settings.xml`:

`deps.edn`

```clojure
:aliases
{:deploy {:replace-deps {slipset/deps-deploy {:mvn/version "0.2.5"}}
          :exec-fn deps-deploy.deps-deploy/deploy
          :exec-args {:installer :remote
                      :artifact "target/docs-clj-1.0.0.jar"
                      :pom-file "target/classes/META-INF/maven/com.example/docs-clj/pom.xml"
                      :sign-releases? false
                      :repository {"cloudrepo" {:url "https://your-org.mycloudrepo.io/repositories/your-repo"}}}}}
```

Run it with the credential set for that one command, using the variables your shell or CI already has:

**Terminal**

```bash
CLOJARS_USERNAME="$CLOUDREPO_USERNAME" CLOJARS_PASSWORD="$CLOUDREPO_TOKEN" clojure -X:deploy
```

Expected: `Deploying com.example/docs-clj-1.0.0 to repository cloudrepo as you@example.com`, the files it sends, and `done.` If the line ends `to repository cloudrepo .` with no `as`, no credential reached deps-deploy and CloudRepo will answer `401`.

> **Do not export CLOJARS_USERNAME or CLOJARS_PASSWORD:** deps-deploy reads these two variables for **every** repository, including clojars.org when a deploy names no repository. Exporting your CloudRepo token under them in your shell or CI job sends it to Clojars the next time you deploy there. Set them on the one command instead, as shown above.

## Overwrite Protection and the 409

A Maven repository guards its releases unless you turn [Overwrite Protection](/docs/manage/repositories.html#overwrite-protection) off. A second deploy of a release version answers `409 Conflict`, and the copy already stored stays untouched. Versions ending in `-SNAPSHOT` are exempt. The rules match Maven’s, described in [Maven Overwrite Protection](/docs/formats/maven.html#maven-overwrite-protection).

Raise the version, or switch to a `-SNAPSHOT` version while you are still iterating.

## Troubleshooting

**`Invalid repo url (http not supported)`.** The Clojure CLI accepts `https://` only. CloudRepo serves `https://your-org.mycloudrepo.io`.

**A private dependency is not found.** Check the repository URL, the artifact’s group and name, and make sure the token has access to this repository and has not expired. See [Troubleshooting](/docs/reference/troubleshooting.html) for `401`, `403` and `404` checks.

**`401 Unauthorized` while resolving.** The `<id>` in `settings.xml` is not the key in `:mvn/repos`, the environment variable is not set in the shell that runs `clojure`, or the username is the wrong email address: it must be the address that owns the token.

**`Execution error (UnsupportedOperationException) ... nth not supported on this type: Character` when publishing.** `:repository` is a string. deps-deploy 0.2.5 accepts only a map, as in the alias above.

**`403 Forbidden`.** The token does not have access to this repository (`scope_mismatch_repo`), or it has **Download packages** access and you are publishing. See [`scope_mismatch_repo`](/docs/reference/error-codes.html#scope_mismatch_repo).

---

The page: https://www.cloudrepo.io/docs/formats/clojure-deps.html
