Dependency Management Plugin Usage memo

What is Dependency Management Plugin?

A Gradle plugin developed by the Spring Project (can you say that?). It is intended to enable the same mechanism as Maven's BOM to be used in Gradle.

The explanation of BOM is [If you want to use BOM with Gradle, it seems better to use Dependency management plugin provided by Spring team-Create something](http://create-something.hatenadiary.jp/entry/2015/05/5 08/063000) etc.

Originally part of the Spring Boot plugin when it was Spring Boot 1.x, it was spun off as a separate plugin when Spring Boot became 2.x. + So it can be used regardless of Spring Boot (but I think the most helpful thing is when using Spring Boot).

environment

Gradle

5.4.1

Dependency Management Plugin

1.0.8.RELEASE

Hello World

build.gradle


plugins {
    id "java"
    id "io.spring.dependency-management" version "1.0.8.RELEASE"
}

repositories {
    mavenCentral()
}

dependencyManagement {
    dependencies {
        dependency "org.apache.commons:commons-lang3:3.9"
    }
}

dependencies {
    implementation "org.apache.commons:commons-lang3"
}

sourceCompatibility = 11
targetCompatibility = 11

compileJava.options.encoding = "UTF-8"

--plugins See https://plugins.gradle.org/plugin/io.spring.dependency-management for how to write without using DSL.

Execution result


> gradle dependencies --configuration runtimeClasspath
...
runtimeClasspath - Runtime classpath of source set 'main'.
\--- org.apache.commons:commons-lang3 -> 3.9

Description

build.gradle


dependencyManagement {
    dependencies {
        dependency "org.apache.commons:commons-lang3:3.9"
    }
}

--Declare dependent libraries up to version with dependencies of dependencyManagement

build.gradle


dependencies {
    implementation "org.apache.commons:commons-lang3"
}

--Then you will be able to omit the version description from the normal project dependency definition. --In this case, the version declared in dependencyManagement will be used by default.

Declare versions of multiple artifacts in the same group at once

build.gradle


...

dependencyManagement {
    dependencies {
        dependencySet(group: "org.apache.poi", version: "4.1.0") {
            entry "poi"
            entry "poi-ooxml"
        }
    }
}

dependencies {
    implementation "org.apache.poi:poi"
    implementation "org.apache.poi:poi-ooxml"
}

...

Execution result


> gradle dependencies --configuration runtimeClasspath
...
runtimeClasspath - Runtime classpath of source set 'main'.
+--- org.apache.poi:poi -> 4.1.0
|    +--- commons-codec:commons-codec:1.12
|    +--- org.apache.commons:commons-collections4:4.3
|    \--- org.apache.commons:commons-math3:3.6.1
\--- org.apache.poi:poi-ooxml -> 4.1.0
     +--- org.apache.poi:poi:4.1.0 (*)
     +--- org.apache.poi:poi-ooxml-schemas:4.1.0
     |    \--- org.apache.xmlbeans:xmlbeans:3.1.0
     +--- org.apache.commons:commons-compress:1.18
     \--- com.github.virtuald:curvesapi:1.06

Description

build.gradle


dependencyManagement {
    dependencies {
        dependencySet(group: "org.apache.poi", version: "4.1.0") {
            entry "poi"
            entry "poi-ooxml"
        }
    }
}

--dependencySet allows you to specify versions of multiple artifacts in the same group at once --The group is ʻorg.apache.poiand the artifacts arepoi and poi-ooxml --Specify4.1.0` as the version

Exclude certain libraries from transitive dependencies

build.gradle


...

dependencyManagement {
    dependencies {
        dependency("org.apache.poi:poi:4.1.0") {
            exclude "commons-codec:commons-codec"
        }
    }
}

dependencies {
    implementation "org.apache.poi:poi"
}

...

Execution result


> gradle dependencies --configuration runtimeClasspath
...
runtimeClasspath - Runtime classpath of source set 'main'.
\--- org.apache.poi:poi -> 4.1.0
     +--- org.apache.commons:commons-collections4:4.3
     \--- org.apache.commons:commons-math3:3.6.1

--Comparing with the dependency graph in the previous section, you can see that commons-codec is gone.

Description

build.gradle


dependencyManagement {
    dependencies {
        dependency("org.apache.poi:poi:4.1.0") {
            exclude "commons-codec:commons-codec"
        }
    }
}

--You can exclude certain libraries in transitive dependencies by using ʻexclude ()`

When specifying with dependencySet

build.gradle


...

dependencyManagement {
    dependencies {
        dependencySet(group: "org.apache.poi", version: "4.1.0") {
            entry("poi") {
                exclude "commons-codec:commons-codec"
            }
            entry "poi-ooxml"
        }
    }
}

dependencies {
    implementation "org.apache.poi:poi"
    implementation "org.apache.poi:poi-ooxml"
}

...

Execution result


> gradle dependencies --configuration runtimeClasspath
...
runtimeClasspath - Runtime classpath of source set 'main'.
+--- org.apache.poi:poi -> 4.1.0
|    +--- org.apache.commons:commons-collections4:4.3
|    \--- org.apache.commons:commons-math3:3.6.1
\--- org.apache.poi:poi-ooxml -> 4.1.0
     +--- org.apache.poi:poi:4.1.0 (*)
     +--- org.apache.poi:poi-ooxml-schemas:4.1.0
     |    \--- org.apache.xmlbeans:xmlbeans:3.1.0
     +--- org.apache.commons:commons-compress:1.18
     \--- com.github.virtuald:curvesapi:1.06

Read the BOM

build.gradle


...

dependencyManagement {
    dependencies {
        imports {
            mavenBom "org.springframework.boot:spring-boot-dependencies:2.1.6.RELEASE"
        }
    }
}

dependencies {
    implementation "org.apache.commons:commons-lang3"
}

...

Execution result


> gradle dependencies --configuration runtimeClasspath
...
runtimeClasspath - Runtime classpath of source set 'main'.
\--- org.apache.commons:commons-lang3 -> 3.8.1

Description

build.gradle


dependencyManagement {
    dependencies {
        imports {
            mavenBom "org.springframework.boot:spring-boot-dependencies:2.1.6.RELEASE"
        }
    }
}

--You can read Maven BOM with mavenBom in ʻimports --Here, [Spring Boot 2.1.6.RELEASE BOM](https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-dependencies/2.1.6.RELEASE) is loaded. --The version ofcommons-lang3 specified in the BOM of 2.1.6.RELEASEis [3.8.1](https://github.com/spring-projects/spring-boot/blob/v2. 1.6.RELEASE/spring-boot-project/spring-boot-dependencies/pom.xml#L51), the resolved version is also3.8.1` --You can also import multiple BOMs --In that case, the version of the same artifact will use the declaration of the last imported BOM.

Overwrite the version declared in the BOM

Overwrite version properties

build.gradle


...
dependencyManagement {
    dependencies {
        imports {
            mavenBom("org.springframework.boot:spring-boot-dependencies:2.1.6.RELEASE") {
                bomProperty "commons-lang3.version", "3.9"
            }
        }
    }
}

dependencies {
    implementation "org.apache.commons:commons-lang3"
}
...

Execution result


> gradle dependencies --configuration runtimeClasspath
...
runtimeClasspath - Runtime classpath of source set 'main'.
\--- org.apache.commons:commons-lang3 -> 3.9

Description

build.gradle


            mavenBom("org.springframework.boot:spring-boot-dependencies:2.1.6.RELEASE") {
                bomProperty "commons-lang3.version", "3.9"
            }

--If the version is declared using a property on the Maven BOM, you can change the version by overwriting the value of that property. --In the Spring Boot BOM, the version of commons-lang3 is [declared] with the property commons-lang3.version (https://github.com/spring-projects/spring-boot/blob/ v2.1.6.RELEASE/spring-boot-project/spring-boot-dependencies/pom.xml#L51) --However, this method should only be used if ** Maven plugin does not output pom.xml ** --Because the information that the version is overwritten is not reflected in the pom.xml output by this method.

There is also a way to write using bomProperties (Map).

bomProperties(Map)Example specified by


dependencyManagement {
    dependencies {
        imports {
            mavenBom("org.springframework.boot:spring-boot-dependencies:2.1.6.RELEASE") {
                bomProperties([
                    "commons-lang3.version": "3.9",
                    "commons-pool2.version": "2.6.1"
                ])
            }
        }
    }
}

Execution result


> gradle dependencies --configuration runtimeClasspath
...
runtimeClasspath - Runtime classpath of source set 'main'.
+--- org.apache.commons:commons-lang3 -> 3.9
\--- org.apache.commons:commons-pool2 -> 2.6.1

You can also declare it with an extended property.

Example specified by extended property


ext["commons-lang3.version"] = "3.8"
ext["commons-pool2.version"] = "2.6.0"

dependencyManagement {
    dependencies {
        imports {
            mavenBom "org.springframework.boot:spring-boot-dependencies:2.1.6.RELEASE"
        }
    }
}

Execution result


> gradle dependencies --configuration runtimeClasspath
...
runtimeClasspath - Runtime classpath of source set 'main'.
+--- org.apache.commons:commons-lang3 -> 3.8
\--- org.apache.commons:commons-pool2 -> 2.6.0

Overwrite dependency management

build.gradle


dependencyManagement {
    dependencies {
        imports {
            mavenBom "org.springframework.boot:spring-boot-dependencies:2.1.6.RELEASE"
        }
        dependency "org.apache.commons:commons-lang3:3.9"
    }
}

dependencies {
    implementation "org.apache.commons:commons-lang3"
}

Execution result


> gradle dependencies --configuration runtimeClasspath
...
runtimeClasspath - Runtime classpath of source set 'main'.
\--- org.apache.commons:commons-lang3 -> 3.9

Description

build.gradle


dependencyManagement {
    dependencies {
        imports {
            mavenBom "org.springframework.boot:spring-boot-dependencies:2.1.6.RELEASE"
        }
        dependency "org.apache.commons:commons-lang3:3.9"
    }
}

--You can override the version declared in the BOM by declaring it with dependency. --Versions declared with dependency take precedence over those declared with a BOM. --Declaring dependency above ʻimportswill give the same result --With this method, the contents of overwriting the version will be reflected in thepom.xml` output by the Maven plugin.

It can also be overridden by specifying the version normally when declaring a dependency.

How to specify the version in the dependency declaration


dependencyManagement {
    dependencies {
        imports {
            mavenBom "org.springframework.boot:spring-boot-dependencies:2.1.6.RELEASE"
        }

        dependency "org.apache.commons:commons-lang3:3.9"
        dependency "org.apache.commons:commons-pool2:2.6.1"
    }
}

dependencies {
    implementation "org.apache.commons:commons-lang3"       //If you do not specify the version
    implementation "org.apache.commons:commons-pool2:2.6.0" //When the version is specified
}

Execution result


> gradle dependencies --configuration runtimeClasspath
...
runtimeClasspath - Runtime classpath of source set 'main'.
+--- org.apache.commons:commons-lang3 -> 3.9
\--- org.apache.commons:commons-pool2:2.6.0

--If you specify a version directly with ʻimplementation, that version is adopted (priority is given to dependency`).

If you want to ignore the version specified directly in the dependency declaration, set the ʻoverriddenByDependencies option to false`.

Ignore if direct version is specified


dependencyManagement {
    overriddenByDependencies = false
    
    dependencies {
        imports {
            mavenBom "org.springframework.boot:spring-boot-dependencies:2.1.6.RELEASE"
        }

        dependency "org.apache.commons:commons-lang3:3.9"
        dependency "org.apache.commons:commons-pool2:2.6.1"
    }
}

dependencies {
    implementation "org.apache.commons:commons-lang3"
    implementation "org.apache.commons:commons-pool2:2.6.0"
}

Execution result


> gradle dependencies --configuration runtimeClasspath
...
runtimeClasspath - Runtime classpath of source set 'main'.
+--- org.apache.commons:commons-lang3 -> 3.9
\--- org.apache.commons:commons-pool2:2.6.0 -> 2.6.1

--The directly specified 2.6.0 was ignored and the 2.6.1 specified in dependency was adopted.

Refer to the properties of the loaded BOM

build.gradle


dependencyManagement {
    dependencies {
        imports {
            mavenBom "org.springframework.boot:spring-boot-dependencies:2.1.6.RELEASE"
        }
    }
}

task showBomProperty {
    doFirst {
        println "commons-lang3.version = ${dependencyManagement.importedProperties["commons-lang3.version"]}"
    }
}

Execution result


> gradle showBomProperty
...
commons-lang3.version = 3.8.1

Description

build.gradle


task showBomProperty {
    doFirst {
        println "commons-lang3.version = ${dependencyManagement.importedProperties['commons-lang3.version']}"
    }
}

--The properties of the loaded BOM can be obtained from dependencyManagement.importedProperties.

Exclusions First, try declaring a dependency on commons-dbcp2 without loading the Spring Boot BOM.

build.gradle


plugins {
    id "java"
}

repositories {
    mavenCentral()
}

dependencies {
    implementation "org.apache.commons:commons-dbcp2:2.5.0"
}
...

Execution result


> gradle dependencies --configuration runtimeClasspath
...
runtimeClasspath - Runtime classpath of source set 'main'.
\--- org.apache.commons:commons-dbcp2:2.5.0
     +--- org.apache.commons:commons-pool2:2.6.0
     \--- commons-logging:commons-logging:1.2

You can see that it contains a dependency on commons-logging.

Next, load the Spring Boot BOM and give it a try.

build.gradle


dependencyManagement {
    dependencies {
        imports {
            mavenBom "org.springframework.boot:spring-boot-dependencies:2.1.6.RELEASE"
        }
    }
}

dependencies {
    implementation "org.apache.commons:commons-dbcp2"
}

Execution result


> gradle dependencies --configuration runtimeClasspath
...
runtimeClasspath - Runtime classpath of source set 'main'.
\--- org.apache.commons:commons-dbcp2 -> 2.5.0
     \--- org.apache.commons:commons-pool2:2.6.0 -> 2.6.2

You can see that the dependency on commons-logging is gone.

This is the Spring Boot BOM, [dependence on commons-logging specified by exclusion](https://github.com/spring-projects/spring-boot/blob/v2.1.6.RELEASE/spring It's happening because of -boot-project / spring-boot-dependencies / pom.xml # L1481).

If you want to stop this behavior (even if it is specified as ʻexclusion in the BOM, you want it to be included as a dependency), set ʻapplyMavenExclusions to false.

build.gradle


dependencyManagement {
    applyMavenExclusions = false
    
    dependencies {
        imports {
            mavenBom "org.springframework.boot:spring-boot-dependencies:2.1.6.RELEASE"
        }
    }
}

dependencies {
    implementation "org.apache.commons:commons-dbcp2"
}

Execution result


> gradle dependencies --configuration runtimeClasspath
...
runtimeClasspath - Runtime classpath of source set 'main'.
\--- org.apache.commons:commons-dbcp2 -> 2.5.0
     +--- org.apache.commons:commons-pool2:2.6.0 -> 2.6.2
     \--- commons-logging:commons-logging:1.2

Dependence on commons-logging has been restored.

Set for each configuration

build.gradle


configurations {
    hoge
    fuga
    piyo
}

dependencyManagement {
    dependencies {
        dependency "org.apache.commons:commons-lang3:3.9"
    }

    hoge {
        dependencies {
            dependency "org.apache.commons:commons-lang3:3.8"
        }
    }

    fuga {
        dependencies {
            dependency "org.apache.commons:commons-lang3:3.8.1"
        }
    }
}

dependencies {
    hoge "org.apache.commons:commons-lang3"
    fuga "org.apache.commons:commons-lang3"
    piyo "org.apache.commons:commons-lang3"
}

Execution result


> gradle dependencies --configuration hoge
...
hoge
\--- org.apache.commons:commons-lang3 -> 3.8

> gradle dependencies --configuration fuga
...
fuga
\--- org.apache.commons:commons-lang3 -> 3.8.1

> gradle dependencies --configuration piyo
...
piyo
\--- org.apache.commons:commons-lang3 -> 3.9

Description

build.gradle


dependencyManagement {
    dependencies {
        dependencies {
            dependency "org.apache.commons:commons-lang3:3.9"
        }
    }

    hoge {
        dependencies {
            dependency "org.apache.commons:commons-lang3:3.8"
        }
    }

    fuga {
        dependencies {
            dependency "org.apache.commons:commons-lang3:3.8.1"
        }
    }
}

--By inserting a script block with the configuration name directly under dependencyManagement, you can declare the dependent version for each configuration. --BOM can be imported for each configuration

Refer to the dependency version

build.gradle


dependencyManagement {
    dependencies {
        imports {
            mavenBom "org.springframework.boot:spring-boot-dependencies:2.1.6.RELEASE"
        }
        dependency "org.apache.commons:commons-pool2:2.6.0"
    }

    testImplementation {
        dependencies {
            dependency "org.apache.commons:commons-lang3:3.9"
            dependency "org.apache.commons:commons-pool2:2.6.1"
        }
    }
}

task showManagedVersions {
    doFirst {
        println """\
        |[default]
        |  commons-lang3 = ${dependencyManagement.managedVersions['org.apache.commons:commons-lang3']}
        |  commons-pool2 = ${dependencyManagement.managedVersions['org.apache.commons:commons-pool2']}
        |
        |[testImplementation]
        |  commons-lang3 = ${dependencyManagement.testImplementation.managedVersions['org.apache.commons:commons-lang3']}
        |  commons-pool2 = ${dependencyManagement.testImplementation.managedVersions['org.apache.commons:commons-pool2']}
        |""".stripMargin()
    }
}

Execution result


> gradle showManagedVersions
...
[default]
  commons-lang3 = 3.8.1
  commons-pool2 = 2.6.0

[testImplementation]
  commons-lang3 = 3.9
  commons-pool2 = 2.6.1

Description

build.gradle


    doFirst {
        println """\
        |[default]
        |  commons-lang3 = ${dependencyManagement.managedVersions['org.apache.commons:commons-lang3']}
        |  commons-pool2 = ${dependencyManagement.managedVersions['org.apache.commons:commons-pool2']}
        |
        |[testImplementation]
        |  commons-lang3 = ${dependencyManagement.testImplementation.managedVersions['org.apache.commons:commons-lang3']}
        |  commons-pool2 = ${dependencyManagement.testImplementation.managedVersions['org.apache.commons:commons-pool2']}
        |""".stripMargin()
    }

--From dependencyManagement.managedVersions, you can see the version of the dependency that was finally resolved. --If you use dependencyManagement. <Configuration> .managedVersions, you can also refer to the information for each configuration.

Things to be aware of when using in a multi-project

There are several ways to overwrite the version declared in the BOM, but the direct dependency method may be ** not used in multi-projects **.

Examples of problems

Suppose you have a Spring Boot application with the following configuration.

Project structure


|-build.gradle
|-settings.gradle
|
|-common/
| |-src/main/java/
| | `-sample/common/
| |   `-CommonComponent.java
| `-build.gradle
|
`-boot/
  |-src/main/java/
  | `-sample/
  |   `-SampleBootApplication.java
  `-build.gradle

--common is an image referenced by multiple projects (here, for simplicity, it is referenced only by the boot project) --boot is a Spring Boot project

CommonComponent.java


package sample.common;

import org.springframework.stereotype.Component;
import org.apache.commons.lang3.ObjectUtils;

@Component
public class CommonComponent {

    public void method(Object obj) {
        System.out.println(ObjectUtils.isEmpty(obj));
    }
}

--Using ʻObjectUtils.isEmpty ()ofcommons-lang3`, it outputs whether the received object is empty or not.

SampleBootApplication.java


package sample;

import sample.common.CommonComponent;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;

@SpringBootApplication
public class SampleBootApplication {

    public static void main(String[] args) {
        try (ConfigurableApplicationContext context = SpringApplication.run(SampleBootApplication.class, args)) {
            CommonComponent common = context.getBean(CommonComponent.class);
            common.method("Hello World");
        }
    }
}

--This is the class that starts Spring Boot --Extracting and executing the previous CommonComponent

Suppose you write each build.gradle of this multi-project as follows:

/build.gradle


plugins {
    id "org.springframework.boot" version "2.1.6.RELEASE" apply false
    id "io.spring.dependency-management" version "1.0.8.RELEASE" apply false
}

subprojects {
    apply plugin: "java"
    apply plugin: "io.spring.dependency-management"

    repositories {
        mavenCentral()
    }

    dependencyManagement {
        dependencies {
            imports {
                mavenBom "org.springframework.boot:spring-boot-dependencies:2.1.6.RELEASE"
            }
        }
    }

    sourceCompatibility = 11
    targetCompatibility = 11

    compileJava.options.encoding = "UTF-8"
}

--The settings common to each project are summarized in subprojects. --Using the Dependency Management Plugin to load the Spring Boot BOM

/common/build.gradle


dependencies {
    implementation "org.springframework:spring-context"
    implementation "org.apache.commons:commons-lang3:3.9"
}

--Declaring the dependency of spring-context because it uses @Component --Also, since ʻObjectUtilsis used, it declares the dependency ofcommons-lang3. -** Here, 3.9 is directly specified for the version of commons-lang3` **

/boot/build.gradle


apply plugin: "org.springframework.boot"

dependencies {
    implementation project(":common")
    implementation "org.springframework.boot:spring-boot-starter"
}

--Since it will be a Spring Boot app, spring-boot-starter is specified as a dependency. --Since it refers to the common project, this is also specified as a dependency.

When you start the application with this setting, it will be as follows.

Execution result


> gradle bootRun
...

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.1.6.RELEASE)

...
2019-07-06 20:06:16.365  INFO 16428 --- [           main] sample.SampleBootApplication             : Started SampleBootApplication in 0.846 seconds (JVM running for 1.335)
Exception in thread "main" java.lang.NoSuchMethodError: org.apache.commons.lang3.ObjectUtils.isEmpty(Ljava/lang/Object;)Z
        at sample.common.CommonComponent.method(CommonComponent.java:10)
        at sample.SampleBootApplication.main(SampleBootApplication.java:14)

> Task :boot:bootRun FAILED

FAILURE: Build failed with an exception.

--Failed with NoSuchMethodError

what happened?

You can see what happened by outputting the dependencies of each project.

#common project dependencies
> gradle :common:dependencies --configuration runtimeClasspath
...
runtimeClasspath - Runtime classpath of source set 'main'.
+--- org.springframework:spring-context -> 5.1.8.RELEASE
|    ...
\--- org.apache.commons:commons-lang3:3.9

#boot project dependencies
> gradle :boot:dependencies --configuration runtimeClasspath
...
runtimeClasspath - Runtime classpath of source set 'main'.
+--- project :common
|    +--- org.springframework:spring-context -> 5.1.8.RELEASE
|    |    ...
|    \--- org.apache.commons:commons-lang3:3.9 -> 3.8.1
\--- org.springframework.boot:spring-boot-starter -> 2.1.6.RELEASE
     ...

--If you look closely, the commons-lang3 in the common project is 3.9, but when viewed from the boot project it is 3.8.1. --By the way, the problematic ʻObjectUtils.isEmpty ()is3.9and [newly added method](https://commons.apache.org/proper/commons-lang/javadocs/api-release/org /apache/commons/lang3/ObjectUtils.html#isEmpty-java.lang.Object-) --When thecommon project is compiled, it refers to 3.9, so it can be compiled without any problem. --But when booting as Spring Boot, the runtimeClasspath of the bootproject is used --As a result,commons-lang3 used at startup became 3.8.1`, and there was no such method, resulting in a runtime error.

Why are the versions different?

/common/build.gradle


dependencies {
    implementation "org.springframework:spring-context"
    implementation "org.apache.commons:commons-lang3:3.9"
}

--The common project will be 3.9 because it directly specifies the version of commons-lang3.

/boot/build.gradle


apply plugin: "org.springframework.boot"

dependencies {
    implementation project(":common")
    implementation "org.springframework.boot:spring-boot-starter"
}

--On the other hand, the boot project does not specifically specify the version of commons-lang3. --Therefore, the 3.8.1 defined in the Spring Boot BOM will be adopted.

How to fix

/build.gradle


plugins {
    id "org.springframework.boot" version "2.1.6.RELEASE" apply false
    id "io.spring.dependency-management" version "1.0.8.RELEASE" apply false
}

subprojects {
    apply plugin: "java"
    apply plugin: "io.spring.dependency-management"

    repositories {
        mavenCentral()
    }

    dependencyManagement {
        dependencies {
            imports {
                mavenBom "org.springframework.boot:spring-boot-dependencies:2.1.6.RELEASE"
            }

            dependency "org.apache.commons:commons-lang3:3.9"
        }
    }

    ...
}

--Changed to specify the version of commons-lang3 in dependencyManagement --This is a setting within subprojects, so it applies to both common and boot projects.

/common/build.gradle


dependencies {
    implementation "org.springframework:spring-context"
    implementation "org.apache.commons:commons-lang3"
}

--Changed build.gradle of common to stop specifying the version

Checking dependencies


#common dependencies
> gradle :common:dependencies --configuration runtimeClasspath
...
runtimeClasspath - Runtime classpath of source set 'main'.
+--- org.springframework:spring-context -> 5.1.8.RELEASE
|    ...
\--- org.apache.commons:commons-lang3 -> 3.9

#boot dependencies
> gradle :boot:dependencies --configuration runtimeClasspath
...
runtimeClasspath - Runtime classpath of source set 'main'.
+--- project :common
|    ...
|    \--- org.apache.commons:commons-lang3 -> 3.9
\--- org.springframework.boot:spring-boot-starter -> 2.1.6.RELEASE
     ...

--It became 3.9 when viewed from boot

Execution result


> gradle bootRun
...
  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.1.6.RELEASE)

...

false

――Of course, even if you execute it, no error will occur.

reference

Recommended Posts

Dependency Management Plugin Usage memo
Spring Security usage memo session management
JavaParser usage memo
WatchService usage memo
PlantUML usage memo
JUnit5 usage memo
Spring Shell usage memo
Spring Security usage memo CSRF
Spring Security usage memo Run-As
Spring Security Usage memo Method security
Personal memo Eclipse plug-in installation
Dependency management in layered architecture
Eclipse 4.8 introduction memo (Plugin edition)
Spring Security usage memo CORS
Spring Security usage memo test
Spring Security usage memo Authentication / authorization
JCA (Java Cryptography Architecture) Usage Memo
Spring Security usage memo response header
Spring Security usage memo Basic / mechanism