use:
Using scope import can solve Maven 's single inheritance problem.
explain:
Maven itself supports inheritance. Many times we will create multi-module projects, and multiple modules will introduce the same dependencies. At this time, we can use Maven 's parent-child project structure. Create a parent pom.xml . The pom.xml files in other projects inherit the parent pom.xml . The content of the pom.xml of the submodule is shown in the following figure:
<parent>
<groupId>com</groupId>
<artifactId>springboot_dubbo</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
Through the above method, we can make our dependency management more regulated. However, the Maven parent-child project structure is the same as Java inheritance, which is single inheritance . A sub-project can only formulate one parent pom . In many cases, we need to break this single inheritance.
For example, when using spring-boot , the official recommended way is to inherit the parent pom , as shown in the following figure:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.4.RELEASE</version>
</parent>
But what if you already have other parent pom in the project and want to use spring-boot ? At this time, you need to use scope import and specify type pom , as shown in the following figure:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.4.RELEASE</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
Note: scope import can only be used in <dependencyManagement> modules .