子pom和父pom

 

转载于:https://www.jianshu.com/p/6215af9801a0

一、在父模块pom中使用的导包方式为:

<!-- 在父pom中的dependencies标签中的jar配置,子pom会直接继承 -->
<depedencies>
  ...
</depedencies>

子模块会直接继承父模块中的jar包
此种方式一般用于:在父pom中配置每个模块都需要的jar包及其他配置信息


二、在父模块pom中使用的导包方式为:

<dependencyManagement>
  <dependencies>
    ...
  </dependencies>
</dependencyManagement>

子模块pom不会自动继承父模块pom中的jar包,如果需要使用,就要给出 groupIdartifactId,无需给出 version
此种方式由父模块统一管理依赖的版本配置


总结

Maven <dependencyManagement> 与 <dependencies> 区别

<dependencies>中的jar直接加到项目中,管理的是依赖关系。(如果有父pom、子pom,则子pom中只能被动接受父pom的版本)

<dependencyManagement>主要管理版本,对于子模块继承同一个父模块是很有用的,集中管理依赖版本不添加依赖关系,对于其中定义的版本,子pom不一定要继承父pom所定义的版本。



作者:缄默_8421
链接:https://www.jianshu.com/p/6215af9801a0
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
原文地址:https://www.cnblogs.com/wsnan/p/12052846.html