maven中的scope与systemPath用法
作者:代码没写完哪有脸睡觉
这篇文章主要介绍了maven中的scope与systemPath用法,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教
maven中的scope与systemPath
scope的分类包括以下
1.maven中scope的默认值是compile。compile表示被依赖项目需要参与当前项目的编译,包括后续的测试,运行周期也参与其中,是一个比较强的依赖。打包的时候通常需要包含进去。
2.test 表示依赖项目仅仅参与测试相关的工作,包括测试代码的编译,执行。比较典型的如junit
3.runtime 表示被依赖项目无需参与项目的编译,不过后期的测试和运行周期需要其参与。与compile相比,跳过编译而已。在终端的项目(非开源,企业内部系统)中,和compile区别不是很大。比较常见的如JSRXXX的实现,对应的API jar是compile,具体实现是runtime的,compile只需要知道接口就足够了。oracle jdbc驱动jar包就是一个很好的例子,一般scope为runtime。 另runtime的依赖通常和optional搭配使用,optional为true。即可以用A实现也可以用B实现。
4.procided 意味着打包的时候可以不用包进去,别的设施(web container)会提供。事实上该依赖理论上可以参与编译、测试、运行等周期。相当于compile,但是打包阶段做了exclude的动作。
5.system 和provide相同,不过被依赖项不会从maven仓库抓,而是从本地系统文件拿,一定要配合systemPath使用
systemPath
当maven依赖本地而非repository中的jar包,systemPath指明本地jar包路径
参考:
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>1.5</version>
<scope>system</scope>
<systemPath>${basedir}/WebContent/WEB-INF/lib/hamcrest-core-1.3.jar</systemPath>
</dependency>
maven scope=system,打包打不进
maven配置
<dependency>
<groupId>xxxx.bigdata</groupId>
<artifactId>data-stream-submit</artifactId>
<version>2.0.0.0</version>
<exclusions>
<exclusion>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
</exclusion>
</exclusions>
<scope>system</scope>
<systemPath>${basedir}/../lib/data-stream-submit-2.0.0.0.jar</systemPath>
</dependency>
maven install lib 没有data-stream-submit 包
解决方案
<build>
<finalName>data-integration</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
// 添加
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>
</plugins>
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。
