maven中使用scope= import

在Spring boot 项目的POM文件中,我们可以通过在POM文件中继承 Spring-boot-starter-parent来引用Srping boot默认依赖的jar包,如下:

1<!-- Inherit defaults from Spring Boot -->
2<parent>
3<groupId>org.springframework.boot</groupId>
4<artifactId>spring-boot-starter-parent</artifactId>
5<version>2.0.1.BUILD-SNAPSHOT</version>
6</parent>


但是,通过上面的parent继承的方法,只能继承一个 spring-boot-start-parent。实际开发中,用户很可能需要继承自己公司的标准parent配置,这个时候可以使用 scope=import 来实现多继承。

代码如下:

 1<dependencyManagement>
 2<dependencies>
 3<dependency>
 4<!-- Import dependency management from Spring Boot -->
 5<groupId>org.springframework.boot</groupId>
 6<artifactId>spring-boot-dependencies</artifactId>
 7<version>2.0.1.BUILD-SNAPSHOT</version>
 8<type>pom</type>
 9<scope>import</scope>
10</dependency>
11</dependencies>
12</dependencyManagement>

通过上面方式,就可以获取spring-boot-dependencies.2.0.1.BUILD-SNAPSHOT.pom文件中dependencyManagement配置的jar包依赖。

如果要继承多个,可以在dependencyManagement中添加,如:

 1<dependencyManagement>
 2<dependencies>
 3<!-- Override Spring Data release train provided by Spring Boot -->
 4<dependency>
 5<groupId>org.springframework.data</groupId>
 6<artifactId>spring-data-releasetrain</artifactId>
 7<version>Fowler-SR2</version>
 8<type>pom</type>
 9<scope>import</scope>
10</dependency>
11<dependency>
12<groupId>org.springframework.boot</groupId>
13<artifactId>spring-boot-dependencies</artifactId>
14<version>2.0.1.BUILD-SNAPSHOT</version>
15<type>pom</type>
16<scope>import</scope>
17</dependency>
18</dependencies>
19</dependencyManagement>












猜你喜欢

转载自blog.csdn.net/leoxyk/article/details/79622507