Skip to content

Maven BOM Provider

jkschneider edited this page Nov 16, 2014 · 5 revisions

The Maven BOM provider sources versions from the dependencyManagement section of a Maven BOM.

As noted in the file-based providers documentation, Maven BOM providers can be loaded from local files, URIs, URLs, dependency artifacts, and the plain InputStream.

apply plugin: 'java'
apply plugin: 'nebula-dependency-recommender'

repositories { mavenCentral() }

dependencyRecommendations {
   mavenBom module: 'sample:sample-bom:1.0'
}

ext['commons.version'] = '1.2'

dependencies {
   compile 'commons-logging:commons-logging'
   compile 'commons-configuration:commons-configuration'
}

Our fictitious BOM looks like this:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>sample</groupId>
  <artifactId>sample-bom</artifactId>
  <version>1.0</version>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>commons-logging</groupId>
        <artifactId>commons-logging</artifactId>
        <version>1.1.1</version>
      </dependency>
      <dependency>
        <groupId>commons-configuration</groupId>
        <artifactId>commons-configuration</artifactId>
        <version>${commons.version}</version>
      </dependency>
    </dependencies>
  </dependencyManagement>
</project>

Evaluating properties in a BOM

Gradle project properties are used as a source during Maven's property resolution process. If the BOM is written to use properties for its versions, you may specify a version through Gradle project properties.

In the example above, the line

ext['commons.version'] = '1.2'

provided the context for the Maven dependency

<dependency>
  <groupId>commons-configuration</groupId>
  <artifactId>commons-configuration</artifactId>
  <version>${commons.version}</version>
</dependency>