maven-pom文件dependence标签

通常情况下,我们引入依赖时,只需要gav三个标签即可
groupId,artifactId,version

有时候我们需要选择引入的依赖是否打包进工程,即需要定义包在项目的使用阶段。
这时候就用到了

scope标签

compile

默认scope为compile,表示为当前依赖参与项目的编译、测试和运行阶段,属于强依赖。项目打包时会把依赖也打进项目的包。

test

该依赖仅仅参与测试相关的内容,包括测试用例的编译和执行,比如定性的junit。

runtime

依赖仅参与运行周期中的使用。一般这种类库都是接口与实现相分离的类库,比如JDBC类库,在编译之时仅依赖相关的接口,在具体的运行之时,才需要具体的mysql、oracle等等数据的驱动程序。
此类的驱动都是为runtime的类库。

provided

该依赖在打包过程中,不需要打进去,这个由运行的环境来提供,比如tomcat或者基础类库等等,事实上,该依赖可以参与编译、测试和运行等周期,与compile等同。区别在于打包阶段进行了exclude操作。

system

使用上与provided相同,不同之处在于该依赖不从maven仓库中提取,而是从本地文件系统中提取,其会参照systemPath的属性进行提取依赖。

systemPath

当maven依赖本地而非repository中的jar包,sytemPath指明本地jar包路径,例如:

<dependency>
    <groupid>com.baomidou</groupid>
    <artifactid>mybatis-plus-boot-starter</artifactid>
    <version>3.1.0</version>
    <scope>system</scope>
    <systempath>本地jar包路径</systempath>
</dependency>

import

这个是maven2.0.9版本后出的属性,import只能在dependencyManagement的中使用,能解决maven单继承问题,import依赖关系实际上并不参与限制依赖关系的传递性。
个人理解:可以类比java中implements
使用import就避免了在父pom中定义冗余的dependencyManagement,直接引入别人定义好的dependencyManagement岂不是美滋滋
使用示例:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-dependencies</artifactId>
    <version>${spring-boot.version}</version>
    <type>pom</type>
    <scope>import</scope>
</dependency>

option标签

官方注释:

Indicates the dependency is optional for use of this library. While the version of the dependency will be taken into account for dependency calculation if the library is used elsewhere, it will not be passed on transitively.

翻译一下就是:这个标签用于声明依赖是否传递

扫描二维码关注公众号,回复: 9542791 查看本文章

举个栗子:
A->B,但option声明true
当X->A时,X需要再次引入B,

参考链接:
https://blog.csdn.net/qq_25933249/article/details/89812785
https://blog.csdn.net/lovejj1994/article/details/80283240

发布了328 篇原创文章 · 获赞 23 · 访问量 7万+

猜你喜欢

转载自blog.csdn.net/lbh199466/article/details/104049442
今日推荐