parent标签 和 dependencyManagement标签
本身 | parent | dependencyManagement |
---|---|---|
pom | pom | |
jar | pom | |
jar | pom |
样例:
spring-boot-starter-parent 本身是一个pom,他的parent是spring-boot-dependencies
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>3.3.3</version>
</parent>
<artifactId>spring-boot-starter-parent</artifactId>
<packaging>pom</packaging>
<name>spring-boot-starter-parent</name>
B项目中,包含parent标签,标签中填写的值是A
如果B是pom类型,A也是pom类型
- 在A项目中,使用dependencyManagement标签,统一管理依赖包的版本,子项目C继承B,就不需要指定依赖包的版本
- 在B项目中build标签中,指定resources 和 pluginManagement,子项目C,直接引用对应的插件,不需要配置插件的版本号、参数等
如果B是jar类型,A是pom类型
- 在B项目中,直接引入依赖,不需要指定版本号;直接引入插件,不需要指定插件版本号和参数
这里需要注意下,如果B是pom类型,A也是pom类型,在B项目中build标签中,指定resources 和 pluginManagement,那么在子项目C,不能再使用dependencyManagement标签,引用B了,因为B配置了resources 和 pluginManagement
分割线---------------------------------------------------------------------分割线--------------------------------------------------------------------------
B项目中,包含dependencyManagement标签,标签中填写的值是A
如果B是pom类型,A也是pom类型
- 在A项目中,使用dependencyManagement标签,统一管理依赖包的版本,子项目C继承B,就不需要指定依赖包的版本
如果B是jar类型,A是pom类型
- 在B项目中,直接引入依赖,不需要指定版本号;直接引入插件,不需要指定插件版本号和参数
通过比较上面的4种情况,可以看出,使用parent标签更强大一点,除了管理依赖,还管理插件。
但是,如果是多module的项目,那么parent必须是业务自身创建的,而业务中依赖包分别来自于开源 和 自行封装。
所以,最好的模式是,专门创建一个iot-dependency 项目中,使用dependencyManagement标签,分别管理开源 和 自行封装 2种依赖包,然后在iot-parent中,使用dependencyManagement标签引入iot-dependency项目