maven中使用scope= import

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

1
2<parent>
3<groupId>org.springframework.bootgroupId>
4<artifactId>spring-boot-starter-parentartifactId>
5<version>2.0.1.BUILD-SNAPSHOTversion>
6parent>


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

代码如下:

 1<dependencyManagement>
 2<dependencies>
 3<dependency>
 4
 5<groupId>org.springframework.bootgroupId>
 6<artifactId>spring-boot-dependenciesartifactId>
 7<version>2.0.1.BUILD-SNAPSHOTversion>
 8<type>pomtype>
 9<scope>importscope>
10dependency>
11dependencies>
12dependencyManagement>

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

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

 1<dependencyManagement>
 2<dependencies>
 3
 4<dependency>
 5<groupId>org.springframework.datagroupId>
 6<artifactId>spring-data-releasetrainartifactId>
 7<version>Fowler-SR2version>
 8<type>pomtype>
 9<scope>importscope>
10dependency>
11<dependency>
12<groupId>org.springframework.bootgroupId>
13<artifactId>spring-boot-dependenciesartifactId>
14<version>2.0.1.BUILD-SNAPSHOTversion>
15<type>pomtype>
16<scope>importscope>
17dependency>
18dependencies>
19dependencyManagement>












你可能感兴趣的:(Spring-boot)