通常工程比较庞大,模块多的时候,在pom.xml文件中,也就是父依赖中会看到dependencyManagement标签。这个标签的作用是:
①对项目所依赖jar包进行版本管理的管理器。
②使用pom.xml中的dependencyManagement元索能让所有在子模块中引用一个依赖而不用显式的列出版本号。也就是子模块不需要列出版本,子模块中的pom依赖会找到dependencyManagement所在jar包的版本,并引用这个jar对应的版本号。
③让子模块不在受繁杂的版本影响,和父pom中的依赖一致即可。
这个是父pom的依赖,定义了jar包的版本号是多少:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>mysq1</groupId>
<artifactId>mysq1 - connector-java< /artifactId>
<version>5.1.2</version>
</dependency>
<dependencies>
</dependencyManagement>
这个是子模块的pom.xml:dependencyManagement直接找到父pom对应jar的版本号。
<dependencies>
<dependency>
<groupId>mysq1</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
</dependencies>
小结:
①dependencyManagement埋只是声明依赖, 并不实现引入,因此子项目需要显示的声明需要用的依赖。
②如果子项目中指定了版本号,那么会使用子项目中指定的jar版本。