maven jar包依赖关系查看、包冲突解决
博客专区 > 4rnold 的博客 > 博客详情
maven jar包依赖关系查看、包冲突解决
4rnold 发表于3个月前
maven jar包依赖关系查看、包冲突解决
  • 发表于 3个月前
  • 阅读 12
  • 收藏 0
  • 点赞 0
  • 评论 0

腾讯云 技术升级10大核心产品年终让利>>>   

在idea中 用maven dependency:tree 运行项目 得到

[INFO] shiro.demo:shiro.demo:war:0.0.2-SNAPSHOT
[INFO] +- junit:junit:jar:4.7:test
[INFO] +- javax.servlet:jstl:jar:1.2:compile
...
...
...
[INFO] |  +- com.mortennobel:java-image-scaling:jar:0.8.6:compile
[INFO] |  |  \- com.jhlabs:filters:jar:2.0.235:compile
[INFO] |  +- javax.servlet:javax.servlet-api:jar:3.1.0:compile
[INFO] |  \- org.apache.shiro:shiro-all:jar:1.2.4:compile
[INFO] |     \- org.apache.shiro:shiro-guice:jar:1.2.4:compile
[INFO] |        +- org.apache.shiro:shiro-core:jar:1.2.4:compile
[INFO] |        +- com.google.inject:guice:jar:3.0:compile
[INFO] |        |  \- javax.inject:javax.inject:jar:1:compile
[INFO] |        \- com.google.inject.extensions:guice-multibindings:jar:3.0:compile
[INFO] +- org.opensymphony.quartz:quartz:jar:1.6.1:compile
[INFO] +- redis.clients:jedis:jar:2.8.0:compile
[INFO] |  \- org.apache.commons:commons-pool2:jar:2.3:compile
[INFO] +- com.fasterxml.jackson.core:jackson-databind:jar:2.7.4:compile
[INFO] +- com.fasterxml.jackson.core:jackson-core:jar:2.7.4:compile
[INFO] \- com.fasterxml.jackson.core:jackson-annotations:jar:2.7.4:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 27.952 s
[INFO] Finished at: 2017-09-02T20:46:05+08:00
[INFO] Final Memory: 15M/116M

可以看到依赖关系。 之前我把shiro相关的dependency都注释掉 项目依然可以运行,原来shiro-freemarker-tags:jar中依赖了shiro相关的包,这样一看就清晰了。

怎么查找所有的重复包呢? 首先需要添加如下插件maven-enforcer-plugin, rules 为DependencyConvergence

<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-enforcer-plugin</artifactId>
   <version>1.4.1</version>
   <executions>
      <execution>
         <id>default-cli</id>
         <configuration>
            <rules>
               <DependencyConvergence/>
            </rules>
         </configuration>
         <goals>
            <goal>enforce</goal>
         </goals>
      </execution>
   </executions>
</plugin>

然后执行 mvn enforcer:enforce 看到茫茫多的包重复

...
[WARNING] 
Dependency convergence error for org.springframework:spring-jdbc:4.2.5.RELEASE paths to dependency are:
+-shiro.demo:shiro.demo:0.0.2-SNAPSHOT
  +-org.springframework:spring-jdbc:4.2.5.RELEASE
and
+-shiro.demo:shiro.demo:0.0.2-SNAPSHOT
  +-org.mybatis:mybatis-spring:1.1.1
    +-org.springframework:spring-jdbc:3.1.1.RELEASE

[WARNING] 
Dependency convergence error for commons-codec:commons-codec:1.6 paths to dependency are:
+-shiro.demo:shiro.demo:0.0.2-SNAPSHOT
  +-org.apache.httpcomponents:httpclient-cache:4.2.5
    +-org.apache.httpcomponents:httpclient:4.2.5
      +-commons-codec:commons-codec:1.6
and
+-shiro.demo:shiro.demo:0.0.2-SNAPSHOT
  +-commons-codec:commons-codec:1.10
and
+-shiro.demo:shiro.demo:0.0.2-SNAPSHOT
  +-commons-httpclient:commons-httpclient:3.1
    +-commons-codec:commons-codec:1.2
and
+-shiro.demo:shiro.demo:0.0.2-SNAPSHOT
  +-net.mingsoft:shiro-freemarker-tags:0.1
    +-commons-codec:commons-codec:1.10
...

有时候包会发生冲突怎么解决冲突呢? 在引入不想要的包的根加上exclusion

<dependency>
	<groupId>net.mingsoft</groupId>
	<artifactId>shiro-freemarker-tags</artifactId>
	<version>0.1</version>
	<exclusions>
		<exclusion>
			<artifactId>shiro-all</artifactId>
			<groupId>org.apache.shiro</groupId>
		</exclusion>
	</exclusions>
</dependency>
标签: shiro maven
共有 人打赏支持
粉丝 0
博文 22
码字总数 10597
×
4rnold
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: