What is the difference between the dependency and dependencyManagement sections in a Maven configuration file?
sobes.tech AI
Answer from AI
In Maven, the <dependencies> and <dependencyManagement> sections serve different purposes:
-
<dependencies>is a list of dependencies that are directly included and used in the current project. Dependencies from this section are automatically added to the classpath during build. -
<dependencyManagement>is a section for centralized management of dependency versions and configurations, but the dependencies themselves are not automatically included. It is usually used in parent POMs or corporate settings to specify versions and parameters for dependencies, which can then be included in child modules without specifying the version.
Example:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.3.20</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<!-- version is not specified, taken from dependencyManagement -->
</dependency>
</dependencies>
Thus, dependencyManagement sets standards and versions, while dependencies actually include the dependencies.