当前位置:网站首页>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 .
边栏推荐
- Volcanic engine: open ByteDance, the same AI infrastructure, a system to solve multiple training tasks
- Basic SQL operations
- MySQL - unique index
- 多表查询之子查询_单行单列情况
- 机器学习小试(10)使用Qt与Tensorflow创建CNN/FNN测试环境
- OSPF含特殊区域实验,MGRE构建和重发布
- This usage, SystemVerilog syntax
- Design of dual machine hot standby scheme
- In depth analysis of common cross end technology stacks of app
- 脚手架内各文件配置说明、组件化开发步骤
猜你喜欢

MySQL——锁

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

Query about operating system security patch information

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

Add a love power logo to your website

Adobe substance 3D Designer 2021 software installation package download and installation tutorial

zoj-Swordfish-2022-5-6

Sentinel implements the persistence of pull pattern rules

Nirvana rebirth! Byte Daniel recommends a large distributed manual, and the Phoenix architecture makes you become a God in fire

ECCV 2022 | 清华提出首个嵌入光谱稀疏性的Transformer
随机推荐
A ten thousand word blog post takes you into the pit. Reptiles are a dead end [ten thousand word pictures]
Sentinel 实现 pull 模式规则持久化
2022, enterprise informatization construction based on Unified Process Platform refers to thubierv0.1
Constant pointer, pointer constant
What does resource pooling and resource pooling mean?
机器学习小试(11)验证码识别测试-使用Qt与Tensorflow2进行深度学习实验
很佩服的一个Google大佬,离职了。。
MySQL performance optimization (IV): how to use indexes efficiently and correctly
Query about operating system security patch information
Google cooperates with colleges and universities to develop a general model, proteogan, which can design and generate proteins with new functions
SQL Server 2012 download and installation detailed tutorial
Erlang studies abroad
[electronic device note 3] capacitance parameters and type selection
ZOJ 2770 differential restraint system -- 2 -- May 20, 2022
fatal: unable to commit credential store: Device or resource busy
Onpropertychange event "suggestions collection"
Uniapp calendar component
Arduino + AD9833 波形发生器
(3) Current situation of low code platform and R & D changes based on it basic components
Association Rules -- July 10, 2022