当前位置:网站首页>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 .
边栏推荐
- Intranet remote control tool under Windows
- Gaode map
- 每日三题 7.22
- MySQL - 唯一索引
- Google cooperates with colleges and universities to develop a general model, proteogan, which can design and generate proteins with new functions
- 二叉树、二叉树排序树的实现及遍历
- IEPE vibration sensor synchronous signal acquisition card /icp synchronous data network acquisition module
- Erlang学习01
- Google Earth engine - QA in Landsat 5 toa dataset_ Pixel and QA_ Radsat band
- Erlang学习02
猜你喜欢

Uniapp calendar component

很佩服的一个Google大佬,离职了。。

PC博物馆(1) 1970年 Datapoint 2000

Sentinel 三种流控模式

Implementation and traversal of binary tree and binary tree sorting tree

Mysql database JDBC programming

MySQL - unique index

图像处理:RGB565转RGB888

IEPE vibration sensor synchronous signal acquisition card /icp synchronous data network acquisition module

火山引擎:开放字节跳动同款AI基建,一套系统解决多重训练任务
随机推荐
Erlang studies abroad
JSON tutorial [easy to understand]
fatal: unable to commit credential store: Device or resource busy
fatal: unable to commit credential store: Device or resource busy
WEB安全基础 - - -文件上传(文件上传绕过)
Sentinel 三种流控模式
ECCV 2022 | 清华提出首个嵌入光谱稀疏性的Transformer
IEPE vibration sensor synchronous signal acquisition card /icp synchronous data network acquisition module
This usage, SystemVerilog syntax
常量指针、指针常量
What does resource pooling and resource pooling mean?
Build a live broadcast platform based on webrtc
给你的网站加一个爱发电角标
Analysis of distributed lock redistribution principle
Gaode map
CMS vulnerability recurrence - foreground arbitrary user password modification vulnerability
binlog、iptables防止nmap扫描、xtrabackup全量+增量备份以及redlog和binlog两者的关系
Figure model 2-2022-5-13
Sentinel 三种流控效果
2022, enterprise informatization construction based on Unified Process Platform refers to thubierv0.1