当前位置:网站首页>Scope usage in POM file dependency
Scope usage in POM file dependency
2022-07-24 10:31:00 【Liu Chu, Ge Nian】
scope
stay Maven The dependent domains in are :compile、provided、runtime、system、test、import
1. compile( Default )
When dependent scope by compile When , So the current dependent package , Will be added when compiling ⼊ Come in , And packing (mvn package) Will also be added ⼊ Come in .
The compilation scope is valid , It will be added when compiling and packaging ⼊ go in .
2. provided
When dependent scope by provided When , It works when compiling and testing , Holding on to ⾏(mvn package) Into the ⾏ You won't add ⼊.
for example : We develop ⼀ individual web Should be ⽤, At compile time, we need to rely on servlet-api.jar, But in transit ⾏ We don't need to jar package , Because of this jar Package already by web Provided by the server , If when packing ⼜ Be added ⼊ go in , Then it may produce ⽣ Conflict . At this point we can make ⽤ provided Into the ⾏ Range modification .
3. system
And provided identical , But being dependent doesn't come from maven Warehouse access ,⽽ It's from local ⽂ The system takes , Need to cooperate with systemPath Attributes use .
such as :
<dependency>
<groupId>org.open</groupId>
<artifactId>open-core</artifactId>
<version>1.5</version>
<scope>system</scope>
<systemPath>${basedir}/WebContent/WEB-INF/lib/open-core.jar</systemPath>
</dependency>
4. runtime
When dependent scope by runtime When , In transit ⾏ Will rely on , When compiling, it will not rely on .⽐ Such as , We don't need to compile JDBC API Of jar package ,⽽ In transit ⾏ When we need JDBC Drive pack . You can use runtime modification .
5. test
When dependent scope by test When , It means that it is valid in the test scope , It won't make ⽤ This dependence .
6. import
maven Multi module items ⽬ In structure , You can make ⽤parent Definition ⽗ term ⽬, from ⽗ term ⽬ Inheritance dependency . but maven Only inheritance , namely ⼀ The item ⽬ Can only make ⽤⼀ individual parent Tag definition ⽗ term ⽬.
maven2.9 Later versions cite ⼊ 了 ⼀ A new feature , Multiple inheritance on dependencies can be realized . This function can make dependency configuration complex pom⽂ Pieces are split into multiple pieces ⽴ Of pom⽂ Pieces of . This treatment can make maven Of pom More concise configuration , At the same time, you can reply ⽤ these pom rely on .
⽐ Such as , We are developing spring boot term ⽬ When ,pom There will be the following configuration in :
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.3.RELEASE</version>
</parent>
however , If this item ⽬ It's a maven⼦ Module , There will be problems . because maven similar java It's single inheritance , There can't be two parent, Now? <parent></parent> The label has ⽤ To quote ⽤⽗ modular , Now? ⼜⽤ To quote ⽤springboot, You'll have ⽣ Conflict .
The solution is : send ⽤dependencyManagement lead ⼊dependency, And the scope Attribute to import. as follows :
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.1.6.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
Be careful :scope Of import Property can only be <dependencyManagement> Chinese envoy ⽤, surface ⽰ From other pom⽂ It's a guide in the process ⼊dependency To configure .
边栏推荐
- Sub query of multi table query_ Single row and single column
- 图模型2--2022-5-13
- pom文件dependency中的 scope用法
- Sentinel implements the persistence of pull pattern rules
- Simply use golang SQLC to generate MySQL query code
- MySQL 数据库 JDBC编程
- Differential restraint system -- 1 and 2 -- May 27, 2022
- MySQL——锁
- 常量指针、指针常量
- PC博物馆(1) 1970年 Datapoint 2000
猜你喜欢

757. Set the intersection size to at least 2: greedy application question

图像处理:RGB565转RGB888

NIO知识点

zoj 2770 差分约束系统---2--2022年5月20日

Query about operating system security patch information

How to solve the problem of robot positioning and navigation in large indoor scenes with low-cost solutions?

差分约束系统---1且2--2022年5月27日

Segment tree--

火山引擎:开放字节跳动同款AI基建,一套系统解决多重训练任务

CMS vulnerability recurrence - foreground arbitrary user password modification vulnerability
随机推荐
Onpropertychange event "suggestions collection"
fatal: unable to commit credential store: Device or resource busy
[electronic device note 4] inductance parameters and type selection
Erlang learning 02
Erlang studies abroad
Scan line, weight segment tree
分布式锁-Redission 原理分析
MySQL performance optimization (IV): how to use indexes efficiently and correctly
Curse of knowledge
[recommendation system] the classic technical architecture of the data flow of the recommendation system + the most complete evolution map of the top 10 deep learning CTR models of Microsoft, Alibaba,
给你的网站加一个爱发电角标
What is NFT? How to develop NFT system?
火山引擎:开放字节跳动同款AI基建,一套系统解决多重训练任务
题解——Leetcode题库第283题
Sentinel 流量控制快速入门
JSON tutorial [easy to understand]
Tree array-
ZOJ 2770 differential restraint system -- 2 -- May 20, 2022
MySQL - 索引的隐藏和删除
[correcting Hongming] what? I forgot to take the "math required course"!