0
votes

In a simple Spring Java project build with Gradle I use io.spring.dependency-management to apply BOM which should dictate dependency versions globally.

Now in BOM I have overridden default version of jackson-databind (2.9.5) from Spring Boot 2.0.2.RELEASE to version 2.9.10.4.

I specify this BOM in dependencyManagement section and expect that jackson-databind will be resolved with 2.9.10.4 version. However that is not the case. If I run gradle dependencies in my subproject it still defines version form Spring Boot 2.0.2.RELEASE:

runtimeClasspath - Runtime classpath of source set 'main'.
\--- com.fasterxml.jackson.core:jackson-databind -> 2.9.5

Is there anything I need to do additionally to enable dependencyManagement?

Here is the build.gradle file

buildscript {
    repositories {
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }
    dependencies {
        classpath 'io.spring.gradle:dependency-management-plugin:1.0.10.RELEASE'
        classpath 'org.springframework.boot:spring-boot-gradle-plugin:2.0.2.RELEASE'
        // ...
    }
}

allprojects {
    repositories {
        mavenLocal()
        mavenCentral()
    }
    apply plugin: 'java'
    apply plugin: 'io.spring.dependency-management'

    dependencyManagement {
        imports {
            mavenBom "com.itshelf:project-bom:1.0.0"
        }
    }
}

subprojects {
        apply plugin: 'org.springframework.boot'
        // ... package Spring fat jar with embedded tomcat into docker image.
}

And BOM definition

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.itshelf</groupId>
  <artifactId>project-bom</artifactId>
  <version>1.0.0</version>
  <packaging>pom</packaging>
  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-dependencies</artifactId>
        <version>2.0.2.RELEASE</version>
        <scope>import</scope>
        <type>pom</type>
      </dependency>
      <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.9.10.4</version>
      </dependency>
      ...
    </dependencies>
  </dependencyManagement>
</project>
1

1 Answers

0
votes

there is no support for the local maven bom file - you have override the explicit lib versions for dependencies. A better idea will be to create a dips-bom.gradle with he explicit versions - basically gradle version of bom.