The difference between Dependencies and Dependency Management

Dependencies and dependencyManagement are often encountered in maven projects. So what is the difference and connection between the two?

Application Scenarios of Depency Management

It is mainly used in multi-module projects, where multiple sub-projects depend on a certain jar package. It is very necessary to ensure that the version of this jar package is consistent. Especially after a package is upgraded, it is not necessary to modify the version number of the dependency one by one in all the used sub-projects. We only need to add the maven coordinates and version number of the dependent jar package in DepencyManagement in the parent project. In the dependencies of the subproject, you only need to add the maven coordinates of the jar package without adding the version again. When updating the version, you only need to update the version in DepencyManagement. Maven will walk up the parent-child hierarchy until it finds a project that has a dependencyManagement element, and then it will use the version number specified in the dependencyManagement element.

Dependencies

Dependencies are jar packages that directly introduce dependencies. If you use Dependencies directly in the parent project of a multi-subproject, it is equivalent to automatically importing these jar dependency packages for all the subprojects below.

the difference

DependencyManagement only declares dependencies, but does not implement imports, so sub-projects need to display the dependencies that need to be declared. If the dependency is not declared in the subproject, it will not be inherited from the parent project; only if the dependency is written in the subproject and no specific version is specified, will the item be inherited from the parent project, and the version and scope Both are read from the parent pom; in addition, if a version number is specified in the subproject, the jar version specified in the subproject will be used.

dependencies Even if the dependency is not written in the subproject, the subproject will still inherit the dependency from the parent project (all inheritance)

Acho que você gosta

Origin blog.csdn.net/aofengdaxia/article/details/122808261
Recomendado
Clasificación