通过Springboot initializer 生成的springboot maven项目中,pom文件会包含parent标签,如下代码
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.0.RELEASE</version>
</parent>
在这种情况下,如果我们构建多module的maven项目,在module工程中,parent标签就冲突了,那怎么解决呢?
假设我们有如下结构的项目。
- parent
- module1
- pom.xml
- module2
- pom.xml
- pom.xml
- module1
最外层pom
最外层的pom.xml写法如下
<modules>
<module>module1</module>
<module>module2</module>
</modules>
<dependencyManagement>
<dependencies>
<dependency>
<!-- Import dependency management from Spring Boot -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${springboot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependencies>
<dependencyManagement>
最外层的pom.xml无需如下parent
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.0.RELEASE</version>
</parent>
module的pom
然后module1以及module2的依赖只需要按需引入依赖的springboot jar即可
<parent>
<artifactId>parent</artifactId>
<groupId>com.xxx</groupId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-test</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependencies>