This example shows how to use Gradle for dependency management. It contains two small projects: A producer that publishes an artifact to Artifactory and a consumer that depends on and downloads the artifact.
Docker is used to run Artifactory.
The example has three parts:
- Start an Artifactory server
- Use Gradle to publish a versioned artifact in the first project
- Use Gradle to consume the versioned artifact in the second project
The example uses a Gradle plugin called VersionedBinaryArtifacts made by Praqma.
Ensure <user home>/.gradle/gradle.properties
has Artifactory properties set as required by the
VersionedBinaryArtifacts
plugin, like this:
$ cat ~/.gradle/gradle.properties
...
repositoryManagerUsername=admin
repositoryManagerPassword=password
repositoryManagerUrl=http://localhost:8081/artifactory
cd infrastructure/artifactory/
./run.sh
Now Artifactory runs in a Docker container available on the URL above. It comes with an example repository called
example-repo-local
. You need to go to the web UI to go through the setup wizard (you can skip all the steps).
cd projects/producer/
./gradlew publish
This puts files in Artifactory by a number of steps:
- Read
build.properties
to run the build command: copy files fromsrc
toout
- Apply the
zip
block defined inbuild.gradle
to create a zip archive of theout
folder - Upload to Artifactory using the repository information in the
gradle.properties
file mentioned earlier, as well as thepublishRepo
andversion
frombuild.properties
cd projects/consumer/
./gradlew resolveDep
This reads build.properties
to download the producer
artifact from Artifactory, along with the gradle.properties
file specifying the connection attributes to Artifactory.
The files are downloaded to the build/resolvedDep
folder.
docker rm -fv artifactory