'What is the purpose of dependency management tag in pom.xml?

Can someone please explain what this dependency do under dependency management and after adding it why we don't need to mention version of our dependencies?

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>


    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>
    </dependencies>


Solution 1:[1]

  • dependencyManagement makes them available, but you need to import them in every submodule you want them loaded into. Works as version control, and avoids a bloated project with all dependencies loaded in every module or child project.

  • dependencies loads them for every module or child who inherits them.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Hayi