一、作用

使用dependencyManagement可以统一管理项目中依赖包的版本号,当需要变更版本号时只需在父pom中修改即可;如果某个子项目需要指定一个特殊的版本号时,只需要在自己项目的pom.xml中显示声明一个版本号即可,此时子项目会使用自己声明的版本号,而不继承父项目的版本号

二、dependencyManagement与dependencies的区别

  • dependencies相对于dependencyManagement,所有声明在dependencies里的依赖都会自动引入,并默认被所有的子项目继承
  • dependencyManagement里只是声明依赖,并不会自动引入,因此子项目需要显示声明依赖。在子项目中声明了依赖项,且没有指定具体版本,才会从父项目中继承该项,并且version和scope都读取自父pom;另外如果子项目中指定了版本号,则会使用子项目中指定的版本

⚠️注意:一个无子工程的独立工程中如果使用dependencyManagement,那么它自己的pom.xml文件引入的依赖也可以不指定版本

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.ume.qa</groupId><artifactId>SpringCloudGateway</artifactId><version>1.0-SNAPSHOT</version><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding><java.version>1.8</java.version><spring-cloud.version>3.0.1</spring-cloud.version></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-webflux</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-gateway</artifactId><version>3.0.3</version></dependency><!--  SpringCloud alibaba nacos    --><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId><exclusions><exclusion><artifactId>spring-cloud-context</artifactId><groupId>org.springframework.cloud</groupId></exclusion><exclusion><artifactId>spring-cloud-commons</artifactId><groupId>org.springframework.cloud</groupId></exclusion><exclusion><artifactId>spring-cloud-starter</artifactId><groupId>org.springframework.cloud</groupId></exclusion></exclusions></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-bootstrap</artifactId></dependency><!--fegin组件--><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-openfeign</artifactId><version>3.0.2</version><exclusions><exclusion><artifactId>spring-cloud-commons</artifactId><groupId>org.springframework.cloud</groupId></exclusion><exclusion><artifactId>spring-cloud-starter</artifactId><groupId>org.springframework.cloud</groupId></exclusion></exclusions></dependency><!-- Feign Client for loadBalancing --><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-loadbalancer</artifactId><version>3.0.2</version><exclusions><exclusion><artifactId>spring-cloud-commons</artifactId><groupId>org.springframework.cloud</groupId></exclusion><exclusion><artifactId>spring-cloud-context</artifactId><groupId>org.springframework.cloud</groupId></exclusion></exclusions></dependency></dependencies><dependencyManagement><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-dependencies</artifactId><version>2.4.2</version><type>pom</type><scope>import</scope></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-dependencies</artifactId><version>${spring-cloud.version}</version><type>pom</type><scope>import</scope></dependency><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-alibaba-dependencies</artifactId><version>2.2.5.RELEASE</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build>
</project>

Maven中dependencyManagement标签的作用相关推荐

  1. Maven中dependencyManagement标签和dependencies的区别

    今天在maven的pom文件中看到了dependencyManagement标签,用法如下: <dependencyManagement><dependencies><d ...

  2. Maven中scope标签的作用

    目录 1 Maven中依赖作用的范围 2 Scope的常见取值 1 Maven中依赖作用的范围 Maven中使用scope标签来指定当前包的依赖性以及传递性,常见的可选值有:compile, prov ...

  3. Maven中dependencyManagement的使用

    本文来说下Maven中dependencyManagement的使用 文章目录 dependencyManagement的使用 dependencyManagement的意义 dependencyMa ...

  4. 在html中base的作用,html中base标签的作用是什么

    html中base标签的作用是什么? 作用:为页面上的所有链接规定默认地址或默认目标,是一种表达路径和连接网址的标签. 说明:通常情况下,浏览器会从当前文档的 URL 中提取相应的元素来填写相对 UR ...

  5. html5用article标记什么意思,html中article标签的作用是什么?

    html中article标签的作用是什么? 发布时间:2020-04-15 14:08:45 来源:亿速云 阅读:508 作者:小新 html中article标签的作用是什么?很多人都不太了解,今天小 ...

  6. cmenu 隐藏子项中的一个子项_区分Maven中dependencyManagement与dependencies的作用

    导读:使用maven是为了更好的帮项目管理包依赖,maven的核心就是pom.xml.而maven中有许多的标签,下面我们主要讨论parent.dependencies与dependencyManag ...

  7. maven中DependencyManagement和Dependencies

    上次这边朋友问我一个问题,就是他们在pom.xml中的dependency中,看到有一些是<scope>provided</scope>的情况,比如如下: 双击代码全选 1 2 ...

  8. pom.xml配置文件中所有标签及作用简单描述

    <project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/200 ...

  9. Maven中scope标签详解

    概述 scope元素的作用:控制 dependency 元素的使用范围.通俗的讲,就是控制 Jar 包在哪些范围被加载和使用.具体值如下: compile:默认值.表示被依赖项目需要参与当前项目的编译 ...

  10. Spring Boot中parent标签的作用

    在Spring Boot的官方示例中,都是让我们继承一个spring的 spring-boot-starter-parent作为parent标签 <parent><groupId&g ...

最新文章

  1. GridView 实现服务器端和客户端全选的两种方法
  2. [sh]shell案例
  3. [翻译] RKCardView
  4. github关联域名,创建个人网站教程终结篇
  5. Educational Codeforces Round 37 (Rated for Div. 2)
  6. 旷视 CVPR 2021 论文解读直播来喽!
  7. MFC 添加文件路径 遍历文件
  8. cURL模拟POST方式提交数据
  9. sql server排序慢_SQL 查询调优之 where 条件排序字段以及 limit 使用索引的奥秘
  10. 应运ajax的几种语言,Ajax指的是什么
  11. JDK动态代理底层剖析
  12. memcache 获取key的方法,查询session存储
  13. [AT2558]Many Moves
  14. python写字_用Python写书法作品,WOW!
  15. 算法设计与分析基础(三)
  16. 基于Java毕业设计高考志愿智能辅助填报系统源码+系统+mysql+lw文档+部署软件
  17. 华为网络工程师认证需要哪些学习资料?
  18. 常用的Sql命令之造数据
  19. python机器学习之决策树案例——泰坦尼克号幸存者的预测
  20. SpringBoot结合Redis实现维护客户端登录状态

热门文章

  1. 用Changedetection监控网页的变化
  2. 【热点资讯】哪所英国大学最适合你?
  3. Linux 下安装 Wordpress教程
  4. bzoj 3772: 精神污染 (主席树+dfs序)
  5. Win10安装Apache和PHP
  6. 教师计算机课教学反思范文,信息技术课优秀教学反思
  7. SAP SLT数据同步配置
  8. 美团2020校招后台开发
  9. svn如何修改443端口
  10. 电视盒子显示ntp服务器异常,云计算-更换VRM主节点所在服务器主板后,出现VRM与NTP服务器状态异常的处理方法...