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>












  • 12
    点赞
  • 29
    收藏
    觉得还不错? 一键收藏
  • 9
    评论
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值