# Use CloudRepo from IntelliJ IDEA

> Point IntelliJ IDEA and the other JetBrains IDEs at CloudRepo for Maven and Gradle builds with a repository token, and fix the 401 that appears in the IDE but not in your terminal.

IntelliJ IDEA runs your Maven and Gradle builds, and CloudRepo is a Maven repository, so there is no CloudRepo setting in the IDE. Set up the build tool, then check that the IDE reads that setup. The same goes for the other JetBrains IDEs, which run the same two build tools.

## Before you start

- A Maven repository. If you have none, [create one](/docs/manage/repositories.html#creating-a-repository).
- A repository token that reaches it. See [Repository tokens](/docs/authenticate/repository-tokens.html). Your username is the email address of the account that created the token, and your password is the token.
- Your repository’s URL, `https://<organization>.mycloudrepo.io/repositories/<repository>`.

## Set up the build tool

**Maven**

**1. Put the credential in `~/.m2/settings.xml`.** The `<id>` is a name you choose, and the repository in your `pom.xml` must use the same one. `${env.CLOUDREPO_TOKEN}` reads the token from an environment variable, so the file holds no 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 your `pom.xml`**, to resolve dependencies from it and to publish to it. Pages for both: [Pull Maven artifacts](/docs/consume/maven.html) and [Publish Maven artifacts](/docs/publish/maven.html).

**3. Tell the IDE which settings file to read.** Open **Settings | Build, Execution, Deployment | Build Tools | Maven** and check the user settings file the IDE uses. It must be the `settings.xml` above.

**4. Give the IDE the token.** The IDE runs Maven in its own environment, and `${env.CLOUDREPO_TOKEN}` is read from there. A program sees the environment variables of the process that started it, so an IDE started from a launcher does not see a variable you exported in a terminal. Either start the IDE from the shell that exports the variable, or set it for the IDE’s Maven runs under **Maven | Runner | Environment variables**.

**Gradle**

**1. Keep the credential in `~/.gradle/gradle.properties`,** outside your project, so it is never committed. The username is your email address, and the password is the token.

`~/.gradle/gradle.properties`

```properties
cloudrepoUsername=you@example.com
cloudrepoToken=YOUR_REPOSITORY_TOKEN
```

**2. Read it in your build script,** to resolve dependencies from CloudRepo and to publish to it. Pages for both: [Pull Gradle dependencies](/docs/consume/gradle.html) and [Publish Gradle artifacts](/docs/publish/gradle.html).

**3. Check the Gradle user home the IDE uses.** Gradle reads `gradle.properties` from its user home, `~/.gradle` unless the environment variable `GRADLE_USER_HOME` says otherwise. IntelliJ shows the Gradle user home it uses under **Settings | Build, Execution, Deployment | Gradle**. It must be the directory that holds the file above.

## Check it from the IDE

Run a build that needs CloudRepo from the IDE’s **Maven** or **Gradle** tool window: resolve a dependency from your repository, or run `deploy` (Maven) or `publish` (Gradle) to publish. If the same build works in a terminal and fails in the IDE, the IDE is not reading the file or the variable you set up above: check the settings named on this page, and that you restarted the IDE after changing an environment variable.

If the build fails with a status, the cause is the one the build tool’s page lists, and it is the same in the IDE. See “When Maven answers 401, 403 or 404” on [Pull Maven artifacts](/docs/consume/maven.html), “When Gradle answers 401, 403 or 404” on [Pull Gradle dependencies](/docs/consume/gradle.html), and the matching list on each publish page.

## A TLS error

CloudRepo serves `*.mycloudrepo.io` with a publicly trusted certificate, so neither the IDE nor its JDK needs a certificate imported to trust it. If your network terminates TLS at a corporate proxy, the certificate the IDE sees is the proxy’s, and the proxy’s certificate authority must be trusted by the JDK the IDE runs on. See JetBrains’ documentation for the IDE’s certificate settings.

More: [Repository tokens](/docs/authenticate/repository-tokens.html), for every client’s credential; [Proxy repositories](/docs/consume/proxy-repositories.html), to resolve Maven Central through CloudRepo; and the [JetBrains documentation for Maven](https://www.jetbrains.com/help/idea/maven-support.html) and [for Gradle](https://www.jetbrains.com/help/idea/gradle-settings.html).

---

The page: https://www.cloudrepo.io/docs/ide/intellij.html
