Gradle Repository

Cloudsmith provides public & private repositories for Gradle

834

Gradle is an open-source build-automation tool that harnesses the power of Maven via a Groovy-based domain-specific language making it easier to define projects and their dependencies.

For more information on Gradle, please see:

  • Gradle: The official website for Gradle
  • Gradle Docs: The official documentation for Gradle
Contextual Documentation

The examples in this document are generic. Cloudsmith provides contextual setup instructions within each repository, complete with copy n' paste snippets (with your namespace/repo pre-configured).

In the following examples:

IdentifierDescription
OWNERYour Cloudsmith account name or organisation name (namespace)
REPOSITORYYour Cloudsmith Repository name (also called "slug")
TOKENYour Cloudsmith Entitlement Token (see Entitlements for more details)
USERNAMEYour Cloudsmith username
PASSWORDYour Cloudsmith password
API-KEYYour Cloudsmith API Key
PACKAGE_VERSIONThe version number of your package
GROUP-IDA unique Maven identifier for your project across all projects i.e "com.companyname.project"
ARTIFACT_IDThe name of the jar without version i.e "project"

📘

These examples use the Groovy-based syntax for Gradle. For the Kotlin syntax, please refer to the official documentation for declaring dependencies.

Upload a Package

Upload via gradle publish

The endpoint for native Gradle API (Maven-based) is:

https://api.cloudsmith.io/maven/

For Maven-based publishing you'll need to enable the maven-publish plugin:

plugins {
  id 'maven-publish'
}

Next, configure a repositories block to point to Cloudsmith as follows:

publishing {
  repositories {
    maven {
      name = "cloudsmith"
      url = "https://api.cloudsmith.io/maven/OWNER/REPOSITORY/"
      def releasesRepoUrl = "https://api.cloudsmith.io/maven/OWNER/REPOSITORY/"
      def snapshotsRepoUrl = "https://api.cloudsmith.io/maven/OWNER/REPOSITORY/"
      url = version.endsWith('SNAPSHOT') ? **snapshotsRepoUrl **: releasesRepoUrl
      credentials {
        username = 'USERNAME'
        password = 'API-KEY'
      }
    }
  }
}

A bare minimum publications section is required:

publishing {
  publications {
    maven(MavenPublication) {
      // [snip]
    }
  }
}

You can now publish to the native API with:

gradle publish

Upload via the Cloudsmith CLI

For full details of how to install and setup the Cloudsmith CLI, see Command Line Interface.

The command to upload via the Cloudsmith CLI is:

cloudsmith push maven OWNER/REPOSITORY ARTIFACT_ID-PACKAGE_VERSION.jar --pom-file=ARTIFACT_ID-PACKAGE_VERSION.pom

Example:

cloudsmith push maven org/repo validation-api-1.0.0.GA.jar --pom-file=validation-api-1.0.0.GA.pom

Upload via Cloudsmith Website

Please see Upload a Package for details of how to upload via the Website UI.


Download / Installing

Setup

To enable the retrieval of Cloudsmith hosted packages via Gradle, the first step is to add your repository to the build.gradle file.

Public Repositories

Add the following, at any location, to your build.gradle file:

repositories {
  maven {
    url "https://dl.cloudsmith.io/public/OWNER/REPOSITORY/maven/"
  }
}

After the repository is added to the build.gradle file, all that is left is to specify the dependency in the dependencies section of the project build.gradle file.

To do this add the below to your build.gradle file:

dependencies {
  implementation 'GROUP_ID:ARTIFACT_ID:PACKAGE_VERSION'
}

Private Repositories

📘

Private Cloudsmith repositories require authentication. You can choose between two types of authentication, Entitlement Token Authentication or HTTP Basic Authentication.

The setup method will differ depending on what authentication type you choose to use.

🚧

Entitlement Tokens, User Credentials and API-Keys should be treated as secrets, and you should ensure that you do not commit them in configurations files along with source code or expose them in any logs

To enable the retrieval of packages from a private Cloudsmith repository via Gradle, add your repository your build.gradle file as follows:

repositories {
  maven {
    url "https://dl.cloudsmith.io/TOKEN/OWNER/REPOSITORY/maven/"
  }
}
repositories {
  maven {
    url "https://dl.cloudsmith.io/basic/OWNER/REPOSITORY/maven/"

    credentials {
      username "$repositoryUser"
      password "$repositoryPassword"
    }
  }
}

When using Entitlement Token Authentication, no further setup is required.
If using HTTP Basic Authentication, you can provide one following three types of credentials:

  • Cloudsmith Username and Password
  • Cloudsmith API Key
  • An Entitlement Token

When using HTTP Basic Authentication you'll probably want to keep your credentials separately in your ~/.gradle/gradle.properties file instead of within the build.gradle file. Once you have decided which credentials you wish to use, setup your ~/.gradle/gradle.properties file as follows:

repositoryUser=USERNAME
repositoryPassword=PASSWORD
repositoryUser=USERNAME
repositoryPassword=API-KEY
repositoryUser=token
repositoryPassword=TOKEN

For more details on authentication in Gradle, please refer to the official Gradle documentation

Specifying Dependencies

After the repository is added to the build.gradle file and your credentials have been added to your ~/.gradle/gradle.properties file (required for private repositories if using HTTP Basic Authentication), all that is left is to specify the dependency in the dependencies section of the project build.gradle file. To do this add the following to your build.gradle file:

dependencies {
  implementation 'GROUP_ID:ARTIFACT_ID:PACKAGE_VERSION'
}

Upstream Proxying / Caching

Configurable Proxying Caching
You can configure upstream repositories that you wish to use for packages that are not available in your Cloudsmith repository. In addition, you can also choose to cache any requested packages for future use.

Please see our Upstream Proxying documentation for further instructions.

Key Signing Support

GPG Index Packages

Troubleshooting

Please see the Troubleshooting Gradle page for further help and information.


Cloudsmith is the new standard in Package / Artifact Management and Software Distribution

With support for all major package formats, you can trust us to manage your software supply chain.


Start My Free Trial Now
Cookie Declaration (Manage Cookies)