spring-bootmavendependency-managementparent-pom

Overriding parent pom dependency through pom import in dependencyManagement


<project>
    <parent>
        <groupId>parent-pom</groupId>
        <artifactId>parent-with-spring-dependencies</artifactId>
        <version>1.0.0</version>
        <relativePath/>
    </parent>

    <modules>
        <module>xxx</module>
        <module>yyy</module>
    </modules>
    
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.xyz.abc</groupId>
                <artifactId>spring-dependencies</artifactId>
                <version>1.0.0</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>    
        </dependencies>

    </dependencyManagement>
    <build>
        <pluginManagement>
    </build>    
</project>

spring-beans is present as a dependency management in parent-pom with version 5.2.0.RELEASE and there is dependencyManagement in spring-dependencies pom where spring-beans version is 5.3.27.

In module xxx spring-beans dependency is present without version and its picking the version present in parent-pom rather than picking it from spring-dependencies present in dependencyManagement, I want version 5.3.27 there. What can I do to achieve that without removing the parent-pom.


Solution

  • If the version in the parent is defined through a property, just override that property.

    If not, add a dependencyManagement entry to your POM that overrides the version. Not by importing another BOM, but by directly specifying it.