This is the Gradle XebiaLabs Dependency Management plugin. When applied to your Gradle project it will be possible to omit version numbers from the specified dependencies, and have them come from imported dependency specification files.
This plugin is not published (yet) to Gradle Plugin Central. It is only available from our Nexus. Please apply the plugin using the following code in the rootProject
build.gradle file.
buildscript {
repositories {
maven {
url "${nexusBaseUrl}/repositories/releases"
credentials {
username nexusUserName
password nexusPassword
}
}
}
dependencies {
classpath "gradle.plugin.com.xebialabs:gradle-xl-dependency-plugin:1.0.0"
}
apply plugin: 'com.xebialabs.dependency'
}
This plugin is the base plugin that doesn’t force any opinions on the project. Note this plugin can only be applied on the rootProject
This plugin builds on top of the com.xebialabs.dependency.base
plugin, and adds the following opinions on top of the xebialabs.dependency.base
plugin:
-
It will take any overridden versions defined on the
rootProject
(See: Version keys as project properties) -
It will load a
${rootProject.projectDir}/gradle/dependencies.conf
file which is required to be present
Using the dependencyManagement
extension it is possible to import configuration files containing dependency information.
-
You can either import a file local to the project
-
You can import a maven dependency using the shortform (
<group_id>:<artifact_id>:<version>
) dependency notation. In this case the plugin will attempt to find the<artifact_id>.conf
file located at that location in the maven repository.
For example:
apply plugin: 'java'
apply plugin: 'xebialabs.dependency'
dependencyManagement {
importConf rootProject.file("path/to/hocon.conf")
importConf "com.xebialabs.xl-platform:xl-reference:${xlPlatformVersion}"
}
repositories {
mavenCentral()
}
dependencies {
compile "org.apache.pekko:pekko-actor_$scalaVersion"
testCompile "junit:junit"
}
The plugin reads the dependency management specification from a HOCON file. Substitutions are allowed inside one file, not across multiple files. The format of the HOCON file should be the following:
dependencyManagement {
versions {
junitVersion: "4.12"
scalaVersion: "2.11"
akkaVersion: "2.3.9"
}
dependencies: [
"junit:junit:$junitVersion"
{
group: "com.typesafe.akka"
version: "$akkaVersion"
artifacts: [
"akka-actor_$scalaVersion"
"akka-testkit_$scalaVersion"
]
}
]
rewrites {
"jdom:jdom": "org.jdom:jdom"
}
blacklist: [
"com.google.collections:google-collections"
]
}
As is shown, there are 4 sections in the conf file.
The versions
section allows you to refer to a version number using a name. In this way you can (potentially) reuse a single version number for different related artifacts. It is a map of key-value pairs.
The dependencies
section is a list of dependencies in either:
-
<group_id>:<artifact_id>:<version>
notation -
a block containing a group of similar artifacts sharing a
group_id
andversion
The placeholders in the strings will be replaced with the data coming from the versions
section.
Each matching dependency in each configuration of each project will be forced to use the version defined in this block.
The rewrites
section contains group:artifact pairs that should be rewritten to a different group:artifact combination. This allows to map moved modules onto their new location.
It is possible to define named versions using project properties. The project property should be of the format: dependencyManagement.versions.<name>
in order to be picked up. See for instance the following example:
dependencyManagement {
versions {
junitVersion: "4.12"
}
dependencies: [
"junit:junit:$junitVersion"
]
}
apply plugin: 'com.xebialabs.dependency.base'
apply plugin: 'java'
dependencyManagement {
supplier com.xebialabs.gradle.dependency.supplier.ProjectSupplier(project)
importConf project.file('reference.conf')
}
dependencies {
testCompile 'junit:junit'
}
If you would launch gradle now using the following command line: gradle build -PdependencyManagement.versions.junitVersion=4.11
, it would force junit to the 4.11
version instead of the 4.12 specified in the reference.conf
file.
The com.xebialabs.dependency
plugin takes care of this automatically.
It is possible to add your own DependencyManagementSupplier
that will supply the dependency management information to the plugin. You can do so by extending the com.xebialabs.gradle.dependency.supplier.DependencyManagementSupplier
.
You can add your own supplier to your build.gradle file using the following snippet:
apply plugin: 'com.xebialabs.dependency.base'
dependencyManagement {
supplier <your class>
}