ARTIFACTORY: How to Mirror Gradle distributions using the Artifactory
A Gradle Distribution archive typically contains the executable application and other supporting files, such as documentation. Using Gradle distributions along with the Gradle Wrapper helps the developers working on the project avoid managing their own Gradle installations.
In this article, we are going to see how to configure Artifactory to mirror Gradle service distribution registry and use it as a source for Gradle distributions.
Repository Configuration
Create a remote generic repository in Artifactory with the URL pointing to https://services.gradle.org/
Artifactory UI → Administrator → Repositories → New Remote Repository → Select Package Type as Generic
Useful Commands
The remote repository listing is not possible, as it is restricted by the provider. However, it is possible to download the distributions using the remote repository URL. Once they are downloaded and cached, it will be listed in the remote repository.
The REST API can be used to list the versions and available versions in the upstream URL.
To list current release:
curl http://localhost:8082/artifactory/gdistribution/versions/current -u username:password
To list the Latest Nightly:
curl http://localhost:8082/artifactory/gdistribution/versions/nightly -u username:password
To list all the available versions:
curl http://localhost:8082/artifactory/gdistribution/versions/all -u username:password
To download a distribution:
wget http://localhost:8082/artifactory/gdistribution/distributions/gradle-8.0.2-all.zip --user username --ask-password
The Artifactory Remote Repository as distribution URL with Gradle WrapperThe remote repository can be used as a distribution URL in the Configuration file: gradle/wrapper/gradle-wrapper.properties
distributionUrl=http\://ARTIFACTORY_HOST/artifactory/<REPO_NAME>/distributions/gradle-<version>.zip
Example
distributionUrl=http\://ARTIFACTORY_HOST/artifactory/<REPO_NAME>/distributions/gradle-8.0.2-all.zip
To set the distribution URL, please use the below command or directly edit the “gradle/wrapper/gradle-wrapper.properties”.
/opt/gradle-7.3.3/bin/gradle wrapper --gradle-distribution-url=http://localhost:8082/artifactory/gdistribution/distributions/gradle-8.0.2-all.zip
Configuration file: gradle/wrapper/gradle-wrapper.properties
distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists distributionUrl=http\://localhost\:8082/artifactory/gdistribution/distributions/gradle-8.0.2-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists
Authentication:If authentication is needed, you can add username and password as system properties when running the Gradle commands or add them to GRADLE_OPTS.
Option1:
./gradlew --version -Dgradle.wrapperUser=<artifactory-username> -Dgradle.wrapperPassword=<artifactory-password>
Option2:
$$ export GRADLE_OPTS="-Dgradle.wrapperUser=$username -Dgradle.wrapperPassword=$password" $$ ./gradlew build
Sample Build$$ ./gradlew build Downloading http://localhost:8082/artifactory/gdistribution/distributions/gradle-8.0.2-all.zip ...............10%................20%................30%................40%................50%................60%................70%................80%................90%................100% Welcome to Gradle 8.0.2! Here are the highlights of this release: - Improvements to the Kotlin DSL - Fine-grained parallelism from the first build with configuration cache - Configurable Gradle user home cache cleanup For more details see https://docs.gradle.org/8.0.2/release-notes.html Starting a Gradle Daemon (subsequent builds will be faster) > Task :buildEnvironment ------------------------------------------------------------ Root project 'test-gradle' ------------------------------------------------------------ classpath No dependencies A web-based, searchable dependency report is available by adding the --scan option. BUILD SUCCESSFUL in 9s 1 actionable task: 1 executed
Cached Artifacts:
Ref: