By now you are familiar with Artifactory repositories, and how to manually upload and download files. Manually downloading files won't really do when developing software. For that we need some proper dependency management, and Gradle is the perfect candidate.
A repository has been set up for you. The name is printed in your terminal when you run setup.sh
, and can also be found in build.gradle
. The repository follows the standard Gradle layout, and it contains two versions of duck.jpg
. We'd like to use this file as a dependency in our program.
Our program is very simple. It takes a given dependency and turns it into a zip file.
The goal of this exercise is to successfully download the latest version of a dependency from Artifactory, and produce an artifact.
- Run
setup.sh
- Navigate to your exercise folder
- Add your gradle repository to
build.gradle
Go to Artifactory and navigate to your $KATA_USERNAME-generic-gradle-1 repository.
- Copy URL to file path from the 'General' page
```groovy
repositories {
maven { url "<Copied from your Artifactory repository General page>"
metadataSources {
artifact()
}
}
}
```
-
Visit Artifactory and find
duck.jpg
in your repository. Modify yourbuild.gradle
so that the file is added as a dependency.Hint: If you visit your artifact in the Artifactory UI, have a look at the
General
tab, underDependency Declaration
. Artifactory has already made the dependency declaration for you, ready to paste into your build script. -
Run
gradle dependencies
and verify that your dependency resolves -
Run
gradle productZip
and verify thatduck.zip
is created. -
Replace
1.0.0
with1.0.+
in your dependency declaration. -
Run
gradle dependencies
again and notice how the newest version is automatically resolved.Hint: If
1.0.0
is still shown as the newest version, you might have to rungradle dependencies --refresh-dependencies
to force the cache to refresh
Congratulations, you can now use artifacts from your own repositories as dependencies in gradle!