聚合项目创建步骤
-
创建父项目,删除src,聚合项目只做管理子工程
-
父项目pom.xml,<packaging>jar</packaging>修改为<packaging>pom</packaging>,因为父项目不是一个具体的包
-
管理子项目,在父项目pom.xml中添加<modules>
<modules>
<module>子项目名</module>
</modules>
Maven继承
子项目会继承所有父项目dependencies标签内以来的jar包
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.4.0</version>
<relativePath/>
</parent>
如果父类里的依赖,并不是要给所有的子项目可以使用<dependencyManagement>
父项目pom.xml
当前标签内不会传递给子项目
<dependencyManagement>
<dependencies>
<dependency>
<groupId></groupId>
<artifactId></artifactId>
<version></version>
</dependency>
</dependencies>
</dependencyManagement>
当前标签内会全部传递给子项目
<dependencies>
<dependency>
<groupId></groupId>
<artifactId></artifactId>
<version></version>
</dependency>
</dependencies>
如果需要引用<dependencyManagement>内包,子项目pom.xml如下设置,不设置<version>,自动继承父类<version>,方便有需要引入的依赖,做版本统一。
子项目pom.xml
<dependencies>
<dependency>
<groupId></groupId>
<artifactId></artifactId>
</dependency>
</dependencies>