Skip to content
Select theme
  • Auto
  • Dark
  • Light

Gradle and Maven

This page is for Gradle and Maven builds. For other formats, see npm, Python, Rust and Cargo, .NET and NuGet, Docker and Helm, and Debian, raw and curl. To publish, see Publish a package.

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.

    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.

    Terminal window
    ./gradlew build

Done when Gradle prints BUILD SUCCESSFUL.

Gradle (Groovy), anyone can download

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

    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.

    Terminal window
    ./gradlew build

Done when Gradle prints BUILD SUCCESSFUL.

Maven, anyone can download

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

    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.

    Terminal window
    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.

    ~/.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.

    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.

    Terminal window
    ./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.

    ~/.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.

    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.

    Terminal window
    ./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.

    ~/.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.

    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.

    Terminal window
    mvn package

Done when Maven prints BUILD SUCCESS.

Find your problem, then do the fix

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 Run in production.

~/.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:

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.