# Gradle and Maven

> Download packages from a Telesphorepo repository in a Gradle or Maven build.

Source: https://docs.telesphorepo.com/download/

This page sets up a Gradle or Maven build to download packages from Telesphorepo. To publish a Gradle or Maven project, see [Publish from a project](/publish-from-a-project/), under Publish your packages.

For other formats, see [npm](/npm/), [Python](/python/), [Rust and Cargo](/cargo/), [.NET and NuGet](/nuget/), [Docker and Helm](/docker/), and [Debian, raw and curl](/debian-and-raw/).

In the blocks, put your server’s address in place of `https://your-server`, and your repository’s name in place of `your-repo`. The **Use this repository** tab of your repository shows the same blocks with your values filled in.

## Gradle (Kotlin), anyone can download

1. Paste this into `build.gradle.kts`, with your package in `dependencies`.

   ```kotlin title="build.gradle.kts"
   repositories {
       maven {
           name = "telesphorepo"
           url = uri("https://your-server/maven/your-repo")
       }
       mavenCentral()
   }

   dependencies {
       implementation("com.example:my-lib:1.0.0")
   }
   ```

2. Run this.

   ```sh
   ./gradlew build
   ```

Done when Gradle prints `BUILD SUCCESSFUL`.

## Gradle (Groovy), anyone can download

1. Paste this into `build.gradle`, with your package in `dependencies`.

   ```groovy title="build.gradle"
   repositories {
       maven {
           name = 'telesphorepo'
           url = 'https://your-server/maven/your-repo'
       }
       mavenCentral()
   }

   dependencies {
       implementation 'com.example:my-lib:1.0.0'
   }
   ```

2. Run this.

   ```sh
   ./gradlew build
   ```

Done when Gradle prints `BUILD SUCCESSFUL`.

## Maven, anyone can download

1. Paste this into `pom.xml`, inside `<project>`, with your package.

   ```xml title="pom.xml"
   <repositories>
     <repository>
       <id>your-repo</id>
       <url>https://your-server/maven/your-repo</url>
     </repository>
   </repositories>

   <dependencies>
     <dependency>
       <groupId>com.example</groupId>
       <artifactId>my-lib</artifactId>
       <version>1.0.0</version>
     </dependency>
   </dependencies>
   ```

2. Run this.

   ```sh
   mvn package
   ```

Done when Maven prints `BUILD SUCCESS`.

## Gradle (Kotlin), only signed-in people can download

1. Make a read token.

   **Settings** › **Tokens** › **New read token**. Type a name, then click **Create token**.

2. Paste your username and the token into `~/.gradle/gradle.properties`.

   ```properties title="~/.gradle/gradle.properties"
   telesphorepoUsername=YOUR_USERNAME
   telesphorepoPassword=YOUR_READ_TOKEN
   ```

   This file is in your home folder, not in the project. It holds your token, so do not commit it.

3. Paste this into `build.gradle.kts`, with your package in `dependencies`.

   ```kotlin title="build.gradle.kts"
   repositories {
       maven {
           name = "telesphorepo"
           url = uri("https://your-server/maven/your-repo")
           credentials(PasswordCredentials::class)
       }
       mavenCentral()
   }

   dependencies {
       implementation("com.example:my-lib:1.0.0")
   }
   ```

4. Run this.

   ```sh
   ./gradlew build
   ```

Done when Gradle prints `BUILD SUCCESSFUL`.

## Gradle (Groovy), only signed-in people can download

1. Make a read token.

   **Settings** › **Tokens** › **New read token**. Type a name, then click **Create token**.

2. Paste your username and the token into `~/.gradle/gradle.properties`.

   ```properties title="~/.gradle/gradle.properties"
   telesphorepoUsername=YOUR_USERNAME
   telesphorepoPassword=YOUR_READ_TOKEN
   ```

   This file is in your home folder, not in the project. It holds your token, so do not commit it.

3. Paste this into `build.gradle`, with your package in `dependencies`.

   ```groovy title="build.gradle"
   repositories {
       maven {
           name = 'telesphorepo'
           url = 'https://your-server/maven/your-repo'
           credentials(PasswordCredentials)
       }
       mavenCentral()
   }

   dependencies {
       implementation 'com.example:my-lib:1.0.0'
   }
   ```

4. Run this.

   ```sh
   ./gradlew build
   ```

Done when Gradle prints `BUILD SUCCESSFUL`.

## Maven, only signed-in people can download

1. Make a read token.

   **Settings** › **Tokens** › **New read token**. Type a name, then click **Create token**.

2. Paste your username and the token into `~/.m2/settings.xml`.

   ```xml title="~/.m2/settings.xml"
   <settings>
     <servers>
       <server>
         <id>your-repo</id>
         <username>YOUR_USERNAME</username>
         <password>YOUR_READ_TOKEN</password>
       </server>
     </servers>
   </settings>
   ```

   This file is in your home folder, not in the project. It holds your token, so do not commit it.

3. Paste this into `pom.xml`, inside `<project>`, with your package.

   ```xml title="pom.xml"
   <repositories>
     <repository>
       <id>your-repo</id>
       <url>https://your-server/maven/your-repo</url>
     </repository>
   </repositories>

   <dependencies>
     <dependency>
       <groupId>com.example</groupId>
       <artifactId>my-lib</artifactId>
       <version>1.0.0</version>
     </dependency>
   </dependencies>
   ```

4. Run this.

   ```sh
   mvn package
   ```

Done when Maven prints `BUILD SUCCESS`.

## If something goes wrong

Gradle or Maven cannot find the package

Use the group, the name and the version of a package in the repository. Open the package in the web UI to see its line.

Gradle or Maven cannot find a public package, such as one of Maven Central

The repository is hosted, and holds your own packages only. Keep `mavenCentral()` in the build, or ask your server admin for a group with a proxy of Maven Central. A Maven group merges the versions of all its members.

401 when you download

The repository is for signed-in people only. Choose **Only signed-in people** above. Check the username and the read token.

There is no New read token button

Read tokens are for accounts with a password. A single sign-on account cannot make one.

Maven refuses an `http://` address

Maven allows `http://` only for `localhost`. Serve the server over HTTPS. See [Serve over HTTPS](/run-the-server/#serve-over-https).

`~/.m2/settings.xml` already has `<servers>`

Add only the `<server>` part to it.

`pom.xml` already has `<repositories>` or `<dependencies>`

Add only the inner part to it.

A CI job must download from a private repository

Keep the read token in a CI secret. For Gradle, set `ORG_GRADLE_PROJECT_telesphorepoUsername` and `ORG_GRADLE_PROJECT_telesphorepoPassword`. For Maven, write `${env.REPO_USERNAME}` and `${env.REPO_TOKEN}` in the `<server>` part, and set those variables.

The repository holds a Gradle plugin

Put the repository in `pluginManagement`, at the top of the settings file:

```kotlin title="settings.gradle.kts"
pluginManagement {
    repositories {
        maven {
            name = "telesphorepo"
            url = uri("https://your-server/maven/your-repo")
        }
        gradlePluginPortal()
    }
}
```

You need a Debian package or a plain file

See [Debian, raw and curl](/debian-and-raw/).
