当前位置:网站首页>pom. XML configuration file label: differences between dependencies and dependencymanagement
pom. XML configuration file label: differences between dependencies and dependencymanagement
2022-07-07 20:00:00 【Whiteye too white】
dependencyManagement Dependency management
Usually in the top-level parent of a project pom Use in dependencyManagement,
Use pom.xml Medium dependencyManagement Element allows all subprojects to reference a dependency without listing the version number . In this way, the dependent version number in the child project will use the parent project pom The dependent version in the file .
When a dependency of a subproject does not specify a version number ,maven Will go up the father and son level , Until you find someone who has dependencyManagement Elements of the project , And then it will use this dependencyManagement The version specified in the element .
The good thing is : If multiple subprojects refer to the same dependency , You can avoid declaring a version number in each used subproject , So when you want to upgrade or switch to another version , Just update in the top-level parent container , It doesn't need to be modified one by one ; In addition, if a sub project requires another version , You just need to be yourself pom Just state the version number in .
Be careful :
- dependencyManagement It's just a statement of dependency , No introduction , So the child project needs to display the required dependencies for the declaration
- If you don't declare dependencies in subprojects , Is not inherited from the parent project ; Only the dependency is written in the subproject , And no specific version was specified , Will inherit the item from the parent project , also version and scope Read from parent pom.
- If the version number is specified in the subproject , Then you will use the... Specified in the subproject jar edition .
dependencies Dependency relationship
Introduce automatic declaration in dependencies All the dependencies in , It is inherited by all subprojects by default . If no dependencies are written in the project , From the parent project
Inherit ( All properties inherit ) Declared in the parent project dependencies Dependencies in .
1. Single module
<!-- Just manage the version number , It won't actually introduce jar-->
<dependencyManagement>
<dependencies>
<dependency>
<!--jar Package identity limit -->
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<!-- Declaration of version number -->
<version>3.2.7</version>
</dependency>
</dependencies>
</dependencyManagement>
<!-- Will actually download the declared dependencies jar package -->
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<!-- Do not declare version label , Will inherit dependencyManagement-->
</dependency>
</dependencies>
2. Multi module situation
Parent module pom.xml
<!--parent-module Parent module pom.xml-->
<properties>
<!-- Unified management jar Package version . Focus on the parent module properties All dependent version numbers are defined in the tag .-->
<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>
<!-- Define the version number of the public dependency -->
<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>
Sub module pom.xml
<!--son-module Sub module pom.xml-->
<!-- Inherited parent class -->
<parent>
<!-- Declare the identity information of the parent class -->
<artifactId>parent-module</artifactId>
<groupId>com.ppd</groupId>
<version>0.0.1-SNAPSHOT</version>
<!-- Declare the of the parent class pom File path -->
<relativePath>../parent-module/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>son-module</artifactId>
<packaging>ejb</packaging>
<!-- Dependency relationship -->
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<!-- If not declared, inherit the parent class version、scope-->
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<!-- Declaration does not inherit the parent class version-->
<version>1.8<version/>
<!-- Inherited parent class scope-->
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.jpa</artifactId>
<!-- If not declared, inherit the parent class version-->
<scope>provided</scope>
</dependency>
</dependencies>
边栏推荐
- vulnhub之tre1
- Kubernetes——kubectl命令行工具用法详解
- gorilla官方:golang开websocket client的示例代码
- torch.nn.functional.pad(input, pad, mode=‘constant‘, value=None)记录
- How to buy bank financial products? Do you need a bank card?
- MSE API学习
- Semantic slam source code analysis
- Notes...
- Classification automatique des cellules de modules photovoltaïques par défaut dans les images de lecture électronique - notes de lecture de thèse
- pom.xml 配置文件标签:dependencies 和 dependencyManagement 区别
猜你喜欢
9 原子操作类之18罗汉增强
Detailed explanation of Flink parallelism and slot
Leetcode force buckle (Sword finger offer 36-39) 36 Binary search tree and bidirectional linked list 37 Serialize binary tree 38 Arrangement of strings 39 Numbers that appear more than half of the tim
Ways to improve the utilization of openeuler resources 01: Introduction
Simulate the implementation of string class
Download from MySQL official website: mysql8 for Linux X Version (Graphic explanation)
Openeuler prize catching activities, to participate in?
Sword finger offer II 013 Sum of two-dimensional submatrix
Nunjuks template engine
Flink并行度和Slot详解
随机推荐
Sword finger offer II 013 Sum of two-dimensional submatrix
openEuler 资源利用率提升之道 01:概论
[confluence] JVM memory adjustment
PMP每日一练 | 考试不迷路-7.7
A pot of stew, a collection of common commands of NPM and yarn cnpm
[RT thread env tool installation]
现在股票开户可以直接在网上开吗?安全吗。
gorilla官方:golang开websocket client的示例代码
Boot 和 Cloud 的版本选型
Install mysql8 for Linux X ultra detailed graphic tutorial
Make this crmeb single merchant wechat mall system popular, so easy to use!
PMP对工作有益吗?怎么选择靠谱平台让备考更省心省力!!!
YoloV6:YoloV6+Win10---训练自己得数据集
vulnhub之Funfox2
9 原子操作类之18罗汉增强
How to cooperate among multiple threads
Semantic slam source code analysis
九章云极DataCanvas公司摘获「第五届数字金融创新大赛」最高荣誉!
R language uses ggplot2 function to visualize the histogram distribution of counting target variables that need to build Poisson regression model, and analyzes the feasibility of building Poisson regr
The state cyberspace Office released the measures for data exit security assessment: 100000 information provided overseas needs to be declared