关于maven的dependency中依赖pom文件的问题

在网上的springcloud教程中,经常看到根pom下有下面这个代码块

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Finchley.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

我的理解是,这只是相当于一个声明,如果在子模块中不显示的在 <dependencies></dependencies>中声明引入,是不会起作用的。但是我发现很多子模块并没有显示引入,那这块的作用是什么?

另外,几遍子模块显示引入,这个也只是pom文件,而不是jar包,有何用?

阅读 5.8k
3 个回答

控制部分依赖的版本,减少依赖版本冲突

集中控制依赖版本
子模块可以直接不添加版本号引入

 <dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-dependencies</artifactId>
</dependency>

多module,或依赖比较复杂的项目,都会定义一个 xxx-parent.pom的文去管理所有这些项目中的jar包版本的一致性,<dependencyManagement> <pluginManagement>都是同理,在父pom中统一管理版本,其他项目依赖这个坐标

<parent>
    <groupId>com.xxx.xxx</groupId>
    <artifactId>xxx-parent</artifactId>
    <version>1.0.0</version>
</parent>

去管理子项目中所有jar包的一致性

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题