Artifactory offers full integration with Gradle via two methods:
Build Server Integration - When running Gradle builds in your continuous integration build server, it is recommended to use one of the Artifactory Plugins for Jenkins, TeamCity or Bamboo to configure resolution and publishing to Artifactory with build-info capturing, via your build server UI.
Standalone Integration - As described below, for when running standalone Gradle build scripts using the Gradle Artifactory plugin. The Gradle Artifactory plugin offers a simple DSL to perform the following as part of your Gradle build:
Define default dependency resolution from Artifactory
Define configurations whose artifacts to be published to Artifactory after a full (multi-module) successful build
Define properties that to be attached to published artifacts in Artifactory metadata
Capture and publish a build-info object to Artifactory build-info REST API to provide a fully traceable build context
Add a repository, which has the plugin and the dependency which includes it. For example:
The above script automatically downloads the plugin and makes it available to the buildScript of your projects.
Adding the Plugin to Your Project(s)
In order to apply the plugin in your Gradle projects, the following closure must be declared in your build.gradle script:
In a multi-project build, you might want to apply the plugin to all projects:
Using the Artifactory Plugin DSL
The Gradle Artifactory plugin can be configured using its own convention DSL inside the build.gradle script of your root project.
The syntax of the Convention DSL is shown below.
Mandatory items within the relevant context are prefixed with '+'. All other items are optional.
The Properties Closure DSL
The properties closure in artifactory.publish.defaults and artifactpryPublish task accept the following syntax:
A configuration that is a valid name of a configuration of the project. You can use all to apply the properties to all configurations.
An artifact specification filter for matching the artifacts to which properties should be attached. The filter may contain wildcards: * for all characters or ? for a single character.
A list of key/value(s) properties that are attached to to the published artifacts matching the filter.
The Artifactory Project Publish Task
Behind the scenes the Gradle Artifactory Plugin creates an 'artifactoryPublish' Gradle task for each project the plugin is applied to.
The artifactoryPublish is configured by the publish closure of the plugin.
You can configure the project-level task directly with the task's artifactoryPublish closure, which uses identical Syntax to that of the plugin's publish closure.
Controlling the Published Modules
To control which modules of a multi-module build are published to Artifactory:
Do not apply the 'artifactory' plugin to project so that it does not publish anything. NOTE! This cannot be performed for the root project that contains the convention object, and so must have the plugin applied.
Manually activate the corresponding 'artifactoryPublish' Gradle task for each project you wish to. For example in our Gradle project example you can run: ./gradlew clean api:artifactory:publish shared:artifactoryPublish
Use the artifactoryPublish.skip flag to deactivate analysis and publication.
Controlling BuildInfo's Build Name and Build Number
By default, BuildInfo is published with a build name that is the name of your root project and a build number that is the start date of the build.
You can control the build name and build number values by specifying the following properties, respectively: