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:
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:
|Your Cloudsmith account name or organisation name (namespace)
|Your Cloudsmith Repository name (also called "slug")
|Your Cloudsmith Entitlement Token (see Entitlements for more details)
|Your Cloudsmith username
|Your Cloudsmith password
|Your Cloudsmith API Key
|The version number of your package
|A unique Maven identifier for your project across all projects i.e "com.companyname.project"
|The 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.
STOP: Note About Gradle's HTTP Connection Pooling
There is a known issue with Gradle and its HTTP connection pooling, affecting publishing (i.e. pushing of packages to Cloudsmith) when using the standard Maven-based upload endpoint.
The HTTP connection pooling in Gradle holds on to IPs for too long, and should the CDN change IP (common with varying points of presence), it will refuse to service the request. To alleviate this, we offer a globally static anycast IP, specifically for this situation.
The endpoint for native Gradle API (Maven-based) is:
For Maven-based publishing you'll need to enable the maven-publish plugin:
Next, configure a repositories block to point to Cloudsmith as follows:
name = "cloudsmith"
url = "https://api-g.cloudsmith.io/maven/OWNER/REPOSITORY/"
def releasesRepoUrl = "https://api-g.cloudsmith.io/maven/OWNER/REPOSITORY/"
def snapshotsRepoUrl = "https://api-g.cloudsmith.io/maven/OWNER/REPOSITORY/"
url = version.endsWith('SNAPSHOT') ? **snapshotsRepoUrl **: releasesRepoUrl
username = 'USERNAME'
password = 'API-KEY'
A bare minimum publications section is required:
You can now publish to the native API with:
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
cloudsmith push maven org/repo validation-api-1.0.0.GA.jar --pom-file=validation-api-1.0.0.GA.pom
Please see Upload a Package for details of how to upload via the Website UI.
To enable the retrieval of Cloudsmith hosted packages via Gradle, the first step is to add your repository to the
Add the following, at any location, to your
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
To do this add the below to your
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:
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:
For more details on authentication in Gradle, please refer to the official Gradle documentation
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:
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.
GPG Index Packages
Please see the Troubleshooting Gradle page for further help and information.
Updated 12 months ago