Maven依赖处理:scope:system

本文探讨了在Maven项目中,当dependency的scope设置为system时,Maven如何处理依赖。通过运行mvn dependency:tree命令,展示了scope为system时,Maven不会包含传递依赖的情况,强调了system scope在管理依赖时的特点。

这两天和同事共同做一个maven的web项目。今天看他改了pom,新引入了依赖

			<groupId>org.talend.esb</groupId>
			<artifactId>atom-rest-client</artifactId>
			<version>5.4.1-20131126135722</version>
			<scope>system</scope>
			<systemPath>${basedir}/libs/atom-rest-client-5.4.1-20131126135722.jar</systemPath>

可以install了之后运行时有ClassNotFound的错误。缺少的正是新引入的jar包,atom-rest-client的依赖。

所以我立刻怀疑是不是scope为system时,Maven就不会处理传递依赖了。查了一下maven依赖树,果然。

在pom目录下,运行mvn dependency:tree

这个是使用默认scope时,项目的依赖树:

[INFO] ------------------------------------------------------------------------
[INFO] Building Service Registry With AngularJS UI 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.1:tree (default-cli) @ NgServiceRegistry ---
[INFO] com.talend.example:NgServiceRegistry:war:1.0-SNAPSHOT
[INFO] +- javax.servlet:servlet-api:jar:2.5:provided
[INFO] +- org.json:json:jar:20131018:compile
[INFO] \- org.talend.esb.tooling:atom-rest-client:jar:5.4.1-SNAPSHOT:compile
[INFO]    +- org.apache.cxf:cxf-rt-frontend-jaxrs:jar:2.6.2:compile
[INFO]    |  +- org.apache.cxf:cxf-api:jar:2.6.2:compile
[INFO]    |  |  +- org.codehaus.woodstox:woodstox-core-asl:jar:4.1.4:runtime
[INFO]    |  |  |  \- org.codehaus.woodstox:stax2-api:jar:3.1.1:runtime
[INFO]    |  |  +- org.apache.ws.xmlschema:xmlschema-core:jar:2.0.3:compile
[INFO]    |  |  +- org.apache.geronimo.specs:geronimo-javamail_1.4_spec:jar:1.7.1:compile
[INFO]    |  |  \- wsdl4j:wsdl4j:jar:1.6.2:compile
[INFO]    |  +- org.apache.cxf:cxf-rt-core:jar:2.6.2:compile
[INFO]    |  |  \- com.sun.xml.bind:jaxb-impl:jar:2.2.5:compile
[INFO]    |  +- javax.ws.rs:jsr311-api:jar:1.1.1:compile
[INFO]    |  +- org.apache.cxf:cxf-rt-bindings-xml:jar:2.6.2:compile
[INFO]    |  \- org.apache.cxf:cxf-rt-transports-http:jar:2.6.2:compile
[INFO]    +- org.apache.cxf:cxf-rt-rs-security-xml:jar:2.6.2:compile
[INFO]    |  \- org.apache.cxf:cxf-rt-ws-security:jar:2.6.2:compile
[INFO]    |     +- org.apache.cxf:cxf-rt-bindings-soap:jar:2.6.2:compile
[INFO]    |     |  \- org.apache.cxf:cxf-rt-databinding-jaxb:jar:2.6.2:compile
[INFO]    |     +- net.sf.ehcache:ehcache-core:jar:2.5.1:compile
[INFO]    |     |  \- org.slf4j:slf4j-api:jar:1.6.1:compile
[INFO]    |     +- org.apache.ws.security:wss4j:jar:1.6.7:compile
[INFO]    |     |  +- org.apache.santuario:xmlsec:jar:1.5.2:compile
[INFO]    |     |  \- org.opensaml:opensaml:jar:2.5.1-1:compile
[INFO]    |     |     \- org.opensaml:openws:jar:1.4.2-1:compile
[INFO]    |     |        \- org.opensaml:xmltooling:jar:1.3.2-1:compile
[INFO]    |     |           \- joda-time:joda-time:jar:1.6.2:compile
[INFO]    |     \- commons-logging:commons-logging:jar:1.1.1:compile
[INFO]    \- rome:rome:jar:1.0:compile
[INFO]       \- jdom:jdom:jar:1.0:compile
[INFO] ------------------------------------------------------------------------
这个是依赖的scope为system时,依赖树的情况:

[INFO] ------------------------------------------------------------------------
[INFO] Building Service Registry With AngularJS UI 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.1:tree (default-cli) @ NgServiceRegistry ---
[INFO] com.talend.example:NgServiceRegistry:war:1.0-SNAPSHOT
[INFO] +- javax.servlet:servlet-api:jar:2.5:provided
[INFO] +- org.json:json:jar:20131018:compile
[INFO] \- org.talend.esb:atom-rest-client:jar:5.4.1-20131126135722:system
[INFO] ------------------------------------------------------------------------

很清楚了吧?当依赖的scope为system时,maven是不会引入依赖的依赖,也就是传递依赖的。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值