当前位置:网站首页>pom.xml 配置文件标签:dependencies 和 dependencyManagement 区别
pom.xml 配置文件标签:dependencies 和 dependencyManagement 区别
2022-07-07 17:52:00 【whiteye太白】
dependencyManagement 依赖管理
通常会在一个项目的最顶层的父pom中使用dependencyManagement,
使用pom.xml中的dependencyManagement元素能让所有子项目在引用一个依赖时不用列出版本号。这样子项目中该依赖的版本号将使用父项目pom文件中该依赖的版本。
子项目某依赖没有指定版本号时,maven会沿着父子层次向上走,直到找到一个拥有dependencyManagement元素的项目,然后它就会使用这个dependencyManagement元素中指定的版本。
这样的好处就是: 如果有多个子项目都引用同一样依赖,则可以避免在每个使用的子项目里都声明一个版本号,这样当想升级或者切换到另一个版本时,只需要在顶层父容器里更新,而不需要一个一个子项目的修改;另外如果某个子项目需要另一个版本,只需要自己pom中声明版本号即可。
注意:
- dependencyManagement里只是声明依赖,并不实现引入,因此子项目需要显示的声明需要用的依赖
- 如果不在子项目中声明依赖,是不会从父项目中继承下来的;只有在子项目中写了该依赖,并且没有指定具体版本,才会从父项目中继承该项,并且version和scope都读取自父pom。
- 如果子项目中指定了版本号,那么会使用子项目中指定的jar版本。
dependencies 依赖关系
自动引入声明在dependencies里的所有依赖,并默认被所有的子项目继承。如果项目中不写依赖项,则会从父项目
继承(属性全部继承)声明在父项目dependencies里的依赖项。
1. 单一模块情况
<!--只是对版本号进行管理,不会实际引入jar-->
<dependencyManagement>
<dependencies>
<dependency>
<!--jar包身份限定-->
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<!--版本号的声明-->
<version>3.2.7</version>
</dependency>
</dependencies>
</dependencyManagement>
<!--会实际下载声明的依赖jar包-->
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<!--不声明version 标签,则会继承dependencyManagement-->
</dependency>
</dependencies>
2. 多模块情况
父模块 pom.xml
<!--parent-module父模块pom.xml-->
<properties>
<!--统一管理jar包版本。集中在父模块properties标签中定义所有依赖的版本号。-->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<org.eclipse.persistence.jpa.version>1.2.6</org.eclipse.persistence.jpa.version>
<javaee-api.version>1.8</javaee-api.version>
</properties>
<dependencyManagement>
<!--定义公共依赖的版本号-->
<dependencies>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.jpa</artifactId>
<version>${org.eclipse.persistence.jpa.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>${javaee-api.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
子模块 pom.xml
<!--son-module子模块pom.xml-->
<!--继承父类-->
<parent>
<!--声明父类的身份信息-->
<artifactId>parent-module</artifactId>
<groupId>com.ppd</groupId>
<version>0.0.1-SNAPSHOT</version>
<!--声明父类的pom文件路径-->
<relativePath>../parent-module/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>son-module</artifactId>
<packaging>ejb</packaging>
<!--依赖关系-->
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<!--未声明则继承父类version、scope-->
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<!--声明则不继承父类version-->
<version>1.8<version/>
<!--继承父类scope-->
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.jpa</artifactId>
<!--未声明则继承父类version-->
<scope>provided</scope>
</dependency>
</dependencies>
边栏推荐
- Browse the purpose of point setting
- 剑指 Offer II 013. 二维子矩阵的和
- 2022.07.04
- Automatic classification of defective photovoltaic module cells in electroluminescence images-論文閱讀筆記
- L1-027 rental (Lua)
- Introduction to bit operation
- 杰理之发起对耳配对、回连、开启可发现、可连接的轮循函数【篇】
- RESTAPI 版本控制策略【eolink 翻译】
- 【Confluence】JVM内存调整
- Netease Yunxin participated in the preparation of the standard "real time audio and video service (RTC) basic capability requirements and evaluation methods" issued by the Chinese Academy of Communica
猜你喜欢

Implement secondary index with Gaussian redis
![[Verilog advanced challenge of Niuke network question brushing series] ~ multi bit MUX synchronizer](/img/7d/ed9a5c536b4cc1913fb69640afb98d.png)
[Verilog advanced challenge of Niuke network question brushing series] ~ multi bit MUX synchronizer

2022如何评估与选择低代码开发平台?

mock. JS returns an array from the optional data in the object array

LeetCode_7_5

Ways to improve the utilization of openeuler resources 01: Introduction

Download from MySQL official website: mysql8 for Linux X Version (Graphic explanation)

转置卷积理论解释(输入输出大小分析)

国家网信办公布《数据出境安全评估办法》:累计向境外提供10万人信息需申报

Kirin Xin'an joins Ningxia commercial cipher Association
随机推荐
Mysql, sqlserver Oracle database connection mode
2022如何评估与选择低代码开发平台?
841. String hash
Navicat连接2002 - Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘解决
Interpretation of transpose convolution theory (input-output size analysis)
Kirin Xin'an joins Ningxia commercial cipher Association
[confluence] JVM memory adjustment
Research and practice of super-resolution technology in the field of real-time audio and video
R语言dplyr包mutate_at函数和min_rank函数计算dataframe中指定数据列的排序序号值、名次值、将最大值的rank值赋值为1
Experiment 1 of Compilation Principle: automatic implementation of lexical analyzer (Lex lexical analysis)
2022.07.02
The strength index of specialized and new software development enterprises was released, and Kirin Xin'an was honored on the list
LeetCode_ 7_ five
openEuler 有奖捉虫活动,来参与一下?
LeetCode 535(C#)
让这个 CRMEB 单商户微信商城系统火起来,太好用了!
PMP每日一练 | 考试不迷路-7.7
微信公众号OAuth2.0授权登录并显示用户信息
【RT-Thread env 工具安装】
位运算介绍