I refer to this post as I googled and still have some questions regarding the differences between using the <dependencies>
XML tag in the pom.xml vs <dependencyManagement>
XML tag in a multi-module Maven project:
https://stackoverflow.com/questions/2619598/differences-between-dependencymanagement-and-dependencies-in-maven#:~:text=Dependency%20Management%20allows%20to%20consolidate,that%20inherits%20a%20common%20parent.
This is a draw.io of the structure of my project - its just a Spring boot/Maven project with a root pom.xml (Parent) and three child modules each with their own POM inheriting from parent POM:
Per that ^ post, it seems that the <dependencyManagement>
tag can be used in multi-module Maven projects to centralize the version, scope etc.. of a dependency. The user stated that you still have to re-declare any dependency in the <dependencyManagement>
enclosing tag AGAIN in the child module... is this true? if so, why not just use the regular enclosing tag in the parent POM, because then all the child modules will inherit this dependency? I tested this myself with the Spring Boot Starter Parent, and I can see by declaring it in the parent POM of my root project, all the dependencies like spring-core, tomcat-embed-core, etc.. are "injected" into my project and all 3 child modules can use these dependencies
I guess I don't clearly understand the advantage to using <dependencyManagement>
tag over regular <dependencies>
. And If I understand the Maven POM inheritance correctly, all the Spring Boot Starter dependencies which are declared in the <parent>
XML tag in my root POM.xml, are injected into my project and can be used by any child module (which is good and what I want). Also, any dependency declared in my root POM.xml with a <dependency>
tag (not inside <dependencyManagement>
tag) will be inherited by all child modules, and if I don't want this behavior, I can simply define the dependency in the specific child module that uses that dependency (to avoid repetition).