一、繼承方式(<parent/>)
父項目A、子項目B。
在子ModuleB 中聲明<parent/>標籤,將父項目A的座標填入,子項目B可以繼承父項目A中的:
1、dependencies: 項目的依賴配置
2、dependencyManagement: 項目的依賴管理配置
3、build: <pluginManagement/>、<plugins/>等
.......
其中需要注意的是dependencies下的必定會繼承,也就是說不需要手動在子項目B的pom中去聲明;而要想使用父項目A dependencyManagement下的依賴,則需要在子項目B中的依賴中聲明(不需要聲明version,但是要聲明groupId、artifactId);
<pluginManagement/>、<plugins/>類似於上面這兩者的關係。
優點:可以繼承父項目的大部分屬性:dependencies、dependencyManagement等。
缺點:單繼承
二、非繼承方式
在項目中的<dependencyManagement/>中可以導入其他pom。例如:
<dependencyManagement> <dependencies> <!--spring boot 2.2.2--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>2.2.2.RELEASE</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>
<type/>和<scope/>固定。
優點:可以導入多個pom。
缺點:只能引用所導入pom的<dependencyManagement/>中的依賴。例如:項目A的<dependencyManagement/>中導入了spring-boot-dependencies的pom,那麼項目A的子項目B只能引用spring-boot-dependencies中的<dependencyManagement/>部分,其他部分無法引用。
以上純屬個人見解,如有不對,感謝指出!共同進步。