Maven的继承问题

maven和Java一样都是单继承机制,也就是在maven的pom文件中也能有一个parent标签(一个父类)
然后父类通过dependencyManagement管理依赖,子类选择性继承
这都是大家熟悉的

那像springboot应用,默认会有一个parent父类spring-boot-starter-parent,但是如果现在想继承其他pom中的依赖,该怎么办呢?

最近在学习springcloud,发现有一种写法,开始也很疑惑,从未见过

 <dependencyManagement>
        <dependencies>
            <!-- <scope>import</scope>解决单继承问题,类似parent标签, -->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Greenwich.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

  
  
   
   
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

通过了解,意思就是,引入(import)spring-cloud-dependencies这个pom文件,然后这个pom中通过dependencyManagement定义了很多依赖,我们就可以选择性继承了(达到类似parent标签的作用,解决了单继承问题)

		<dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
            <!-- 这里会自动引入版本,类似parent标签继承 -->
        </dependency>

  
  
   
   
  • 1
  • 2
  • 3
  • 4
  • 5

所以这个我不需要写版本号,直接是从import(引入)进来的pom文件中继承得到的

猜你喜欢

转载自blog.csdn.net/qq_15098623/article/details/103344834