我的编程空间,编程开发者的网络收藏夹
学习永远不晚

关于Maven依赖冲突解决之exclusions

短信预约 -IT技能 免费直播动态提醒
省份

北京

  • 北京
  • 上海
  • 天津
  • 重庆
  • 河北
  • 山东
  • 辽宁
  • 黑龙江
  • 吉林
  • 甘肃
  • 青海
  • 河南
  • 江苏
  • 湖北
  • 湖南
  • 江西
  • 浙江
  • 广东
  • 云南
  • 福建
  • 海南
  • 山西
  • 四川
  • 陕西
  • 贵州
  • 安徽
  • 广西
  • 内蒙
  • 西藏
  • 新疆
  • 宁夏
  • 兵团
手机号立即预约

请填写图片验证码后获取短信验证码

看不清楚,换张图片

免费获取短信验证码

关于Maven依赖冲突解决之exclusions

Maven依赖冲突解决之exclusions

1. 背景

  • 作为java生态下开发者,往往需要使用大量线程的第三方库,一般都是以jar包形式存在。
  • maven作为事实上主流的jar包依赖管理工具,Idea和Eclipse都支持创建maven工程来管理jar包依赖。
  • 使用maven进行jar包依赖管理时,maven会自行管理jar包及其依赖链条,但往往会遇到依赖冲突问题,这时候就可以尝试使用exclusion来进行依赖管理。

2. 解决方式

场景

在这里插入图片描述

假如hadoop集群中hadoop版本是3.2.1,这时候为了保证程序能够顺利操作hadoop,需要引入hadoop-client的3.2.1版本。但这里也可以看到,spark-core_2.12内部也有对hadoop-client的依赖,而且版本是低版本的2.7.4,这时候往往就会产生冲突或者未知错误。所以需要使用exclusions做依赖排除。

解决方式

使用exclusions来对某一个第三方库引入的依赖jar包做排除


<dependency>
            <groupId>org.apache.spark</groupId>
            <artifactId>spark-core_2.12</artifactId>
            <version>${spark.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>org.apache.hadoop</groupId>
                    <artifactId>hadoop-client</artifactId>
                </exclusion>

                <exclusion>
                    <groupId>com.google.guava</groupId>
                    <artifactId>guava</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

在这里插入图片描述

Maven解决依赖冲突总结

如果存在jar包的依赖冲突,在项目启动时总是报类似这样的错:NoSuchMethodError、ClassNotFoundException、成员变量找不到等等。真的很让人不好受。

Maven采用的是“最近获胜的策略”来处理依赖的冲突,即如果一个项目最终依赖于相同artifact的多个版本,在依赖树中离项目最近的那个版本将被使用。让我们来看看一个实际的例子。

实例分析

我们有一个web应用resolve-web,该工程依赖于project-A和project-B,project-A依赖于project-common的1.0版本并调用其中的sayHello()方法。project-B依赖于project-C,而project-C又进一步依赖于project-common的2.0版本并调用其中的sayGoodBye()方法。project-common的1.0和2.0版本是不同的,1.0中之包含sayHello()方法,而2.0中包含了sayHello()和sayGoodBye()两个方法。整个项目的依赖关系如下图:

根据Maven的最近原则依赖机制,resolve-web将同时依赖于project-common的1.0和2.0版本,这就造成了依赖冲突。而根据最近获胜策略,Maven将选择project-common的1.0版本作为最终的依赖。这和Gradle不同,Gradle在默认情况下将选择最新的版本作为获胜版本。而对于Maven,由于proejct-common的1.0版本比2.0版本在依赖树中离resolve-web更近,故1.0版本获胜。在resolve-web中执行"mvn dependency:tree -Dverbose"可以看到resolve-web的依赖关系:


[INFO] resolve-web:resolve-web:war:1.0-SNAPSHOT
 
[INFO] +- junit:junit:jar:3.8.1:test
 
[INFO] +- project-B:project-B:jar:1.0:compile
 
[INFO] |  \- project-C:project-C:jar:1.0:compile
 
[INFO] |     \- (project-common:project-commmon:jar:2.0:compile - omitted for conflict with 1.0)
 
[INFO] +- project-A:project-A:jar:1.0:compile
 
[INFO] |  \- project-common:project-commmon:jar:1.0:compile
 
[INFO] \- javax.servlet:servlet-api:jar:2.4:provided

由上可知,project-common:project-commmon:jar:2.0被忽略掉了。此时在resolve-web的war包中将只包含project-common的1.0版本,于是问题来了。由于project-common的1.0版本中不包含sayGoodBye()方法,而该方法正是project-C所需要的,所以运行时将出现“NoSuchMethodError”。

解决办法

方法1:显式加入对project-common 2.0版本的依赖。先前的2.0版本不是离resolve-web远了点吗,那我们就直接将它作为resolve-web的依赖,这不就比1.0版本离resolve-web还近吗?在resove-web的pom.xml文件中直接加上对project-common 2.0 的依赖


<dependency>       
   <groupId>project-common</groupId>      
   <artifactId>project-commmon</artifactId>  
   <version>2.0</version>   
</dependency>  

方法2:resolve-web对project-A的dependency声明中,将project-common排除掉。在resolve-web的pom.xml文件中修改对project-A的dependency声明


<dependency>  
          <groupId>project-A</groupId>  
          <artifactId>project-A</artifactId>  
          <version>1.0</version>  
          <exclusions>  
              <exclusion>  
                  <groupId>project-common</groupId>  
                  <artifactId>project-commmon</artifactId>  
              </exclusion>  
          </exclusions>  
</dependency>

此时再在resolve-web中执行"mvn dependency:tree -Dverbose",如下:


......
 
[INFO] resolve-web:resolve-web:war:1.0-SNAPSHOT
 
[INFO] +- junit:junit:jar:3.8.1:test
 
[INFO] +- project-B:project-B:jar:1.0:compile
 
[INFO] |  \- project-C:project-C:jar:1.0:compile
 
[INFO] |     \- project-common:project-commmon:jar:2.0:compile
 
[INFO] +- project-A:project-A:jar:1.0:compile
 
[INFO] \- javax.servlet:servlet-api:jar:2.4:provided
 
......

这样的话,就可以完美解决冲突了。

命令分析

这里我们对我们执行的命令做一个简单的说明。


mvn dependency:tree -Dverbose -Dincludes=<groupId>:<artifactId>

1、第一部分mvn dependency:tree是maven依赖的分析命令,作用是对我们的项目的依赖进行分析,并输出项目依赖树

2、第二部分-Dverbose的作用是添加了verbose一个环境变量,起的作用是在分析项目依赖时输出明细,这样项目中依赖的所有3、引用都会被输出出来,包含了所有的间接引用,会有很多很多,我们只需要我们要找的,所以就需要第三个参数了第三部分-Dincludes=<groupId>:<artifactId>的作用就是进行过滤,只包含我们想要的依赖的依赖时,排除掉其它不需要的,依赖树的所有叶子节点就是我们的找的依赖包。其中的groupId和artifactId可以只填写一个,为了保证准确性,一般都会填两个(填写时不包括尖括号)。

小试牛刀

在自己的项目上,启动时发现如下异常:

21-Mar-2019 15:51:33.527 信息 [RMI TCP Connection(2)-127.0.0.1] org.apache.catalina.core.ApplicationContext.log Initializing Spring root WebApplicationContext
21-Mar-2019 15:52:08.905 严重 [RMI TCP Connection(2)-127.0.0.1] org.apache.catalina.core.StandardContext.listenerStart Exception sending context initialized event to listener instance of class [org.springframework.web.context.ContextLoaderListener]
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.socket.server.support.WebSocketHandlerMapping#0': Cannot resolve reference to bean 'org.springframework.web.socket.sockjs.support.SockJsHttpRequestHandler#0' while setting bean property 'urlMap' with key [/websocket/**]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.socket.sockjs.support.SockJsHttpRequestHandler#0': Cannot resolve reference to bean 'org.springframework.web.socket.sockjs.transport.handler.DefaultSockJsService#0' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.socket.sockjs.transport.handler.DefaultSockJsService#0': Cannot resolve reference to bean 'SockJsScheduler' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'SockJsScheduler': Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'removeOnCancelPolicy' of bean class [org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler]: Bean property 'removeOnCancelPolicy' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveManagedMap(BeanDefinitionValueResolver.java:407)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:165)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1531)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1276)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:443)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:325)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4817)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5283)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:754)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:730)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1736)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:300)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:483)
at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:432)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:300)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
at com.sun.jmx.remote.security.MBeanServerAccessController.invoke(MBeanServerAccessController.java:468)
at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1468)
at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:76)
at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1309)
at java.security.AccessController.doPrivileged(Native Method)
at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1408)
at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:829)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:357)
at sun.rmi.transport.Transport$1.run(Transport.java:200)
at sun.rmi.transport.Transport$1.run(Transport.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:573)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:834)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:688)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:687)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)

执行命令分析下,项目的jar包的依赖情况,只过滤并分析spring框架的jar包依赖树情况,使用的命令如下:


mvn dependency:tree -Dverbose -Dincludes=org.springframework:

在新引入的项目jar包中,发现其再次引入了spring的相关包并且该spring包的层级属于第二层级,实际已有的spring的包处在第三或者第四层级,根据就近原则,低版本的3.2.5的jar包覆盖了高版本的jar包,导致出现找不到某变量的异常。剔除这些jar包如下配置:


<exclusion>
       <groupId>org.springframework</groupId>
       <artifactId>spring-beans</artifactId>
</exclusion>
<exclusion>
       <groupId>org.springframework</groupId>
       <artifactId>spring-context</artifactId>
</exclusion>
<exclusion>
       <groupId>org.springframework</groupId>
       <artifactId>spring-context-support</artifactId>
</exclusion>

重新查看jar包的依赖树:


xujiaqingdeMacBook-Pro:mos jaycee$ mvn dependency:tree -Dverbose -Dincludes=org.springframework:
[WARNING] 
[WARNING] Some problems were encountered while building the effective settings
[WARNING] Unrecognised tag: 'mirror' (position: START_TAG seen ...e the preferred\n   | server for that repository.\n   |-->\n <mirror>... @153:10)  @ /software/apache-maven-3.6.0/conf/settings.xml, line 153, column 10
[WARNING] 
[INFO] Scanning for projects...
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for fish:core-db:jar:1.0-SNAPSHOT
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing. @ fish:core-db:[unknown-version], /projects/mos/core-db/pom.xml, line 79, column 21
[WARNING] 
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING] 
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING] 
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO] 
[INFO] FishParent                                                         [pom]
[INFO] core-db                                                            [jar]
[INFO] core                                                               [war]
[INFO] 
[INFO] --------------------------< fish:FishParent >---------------------------
[INFO] Building FishParent 1.0-SNAPSHOT                                   [1/3]
[INFO] --------------------------------[ pom ]---------------------------------
[INFO] 
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ FishParent ---
[INFO] 
[INFO] ----------------------------< fish:core-db >----------------------------
[INFO] Building core-db 1.0-SNAPSHOT                                      [2/3]
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ core-db ---
[INFO] fish:core-db:jar:1.0-SNAPSHOT
[INFO] \- com.hand:hap-db:jar:3.5.4-RELEASE:compile
[INFO]    \- com.hand:hap-core-db:jar:3.5.4-RELEASE:compile
[INFO]       \- org.springframework:spring-core:jar:4.3.11.RELEASE:compile
[INFO] 
[INFO] -----------------------------< fish:core >------------------------------
[INFO] Building core 1.0-SNAPSHOT                                         [3/3]
[INFO] --------------------------------[ war ]---------------------------------
[INFO] 
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ core ---
[INFO] fish:core:war:1.0-SNAPSHOT
[INFO] +- com.hand:hap-db:jar:3.5.4-RELEASE:compile
[INFO] |  \- com.hand:hap-core-db:jar:3.5.4-RELEASE:compile
[INFO] |     \- org.springframework:spring-core:jar:4.3.11.RELEASE:compile
[INFO] +- com.hand:hap-pom:pom:3.5.4-RELEASE:provided
[INFO] |  +- com.hand:hap-core:jar:classes:3.5.4-RELEASE:provided
[INFO] |  |  +- (org.springframework:spring-core:jar:4.3.11.RELEASE:provided - omitted for duplicate)
[INFO] |  |  +- org.springframework:spring-jdbc:jar:4.3.11.RELEASE:provided
[INFO] |  |  |  +- org.springframework:spring-beans:jar:4.3.11.RELEASE:provided
[INFO] |  |  |  |  \- (org.springframework:spring-core:jar:4.3.11.RELEASE:provided - omitted for duplicate)
[INFO] |  |  |  +- (org.springframework:spring-core:jar:4.3.11.RELEASE:provided - omitted for duplicate)
[INFO] |  |  |  \- (org.springframework:spring-tx:jar:4.3.11.RELEASE:provided - omitted for duplicate)
[INFO] |  |  +- org.springframework:spring-test:jar:4.3.11.RELEASE:provided
[INFO] |  |  |  \- (org.springframework:spring-core:jar:4.3.11.RELEASE:provided - omitted for duplicate)
[INFO] |  |  +- org.springframework:spring-context:jar:4.3.11.RELEASE:provided
[INFO] |  |  |  +- org.springframework:spring-aop:jar:4.3.11.RELEASE:provided
[INFO] |  |  |  |  +- (org.springframework:spring-beans:jar:4.3.11.RELEASE:provided - omitted for duplicate)
[INFO] |  |  |  |  \- (org.springframework:spring-core:jar:4.3.11.RELEASE:provided - omitted for duplicate)
[INFO] |  |  |  +- (org.springframework:spring-beans:jar:4.3.11.RELEASE:provided - omitted for duplicate)
[INFO] |  |  |  +- (org.springframework:spring-core:jar:4.3.11.RELEASE:provided - omitted for duplicate)
[INFO] |  |  |  \- org.springframework:spring-expression:jar:4.3.11.RELEASE:provided
[INFO] |  |  |     \- (org.springframework:spring-core:jar:4.3.11.RELEASE:provided - omitted for duplicate)
[INFO] |  |  +- org.springframework:spring-context-support:jar:4.3.11.RELEASE:provided
[INFO] |  |  |  +- (org.springframework:spring-beans:jar:4.3.11.RELEASE:provided - omitted for duplicate)
[INFO] |  |  |  +- (org.springframework:spring-context:jar:4.3.11.RELEASE:provided - omitted for duplicate)
[INFO] |  |  |  \- (org.springframework:spring-core:jar:4.3.11.RELEASE:provided - omitted for duplicate)
[INFO] |  |  +- org.springframework:spring-web:jar:4.3.11.RELEASE:provided
[INFO] |  |  |  +- (org.springframework:spring-aop:jar:4.3.11.RELEASE:provided - omitted for duplicate)
[INFO] |  |  |  +- (org.springframework:spring-beans:jar:4.3.11.RELEASE:provided - omitted for duplicate)
[INFO] |  |  |  +- (org.springframework:spring-context:jar:4.3.11.RELEASE:provided - omitted for duplicate)
[INFO] |  |  |  \- (org.springframework:spring-core:jar:4.3.11.RELEASE:provided - omitted for duplicate)
[INFO] |  |  +- org.springframework:spring-webmvc:jar:4.3.11.RELEASE:provided
[INFO] |  |  |  +- (org.springframework:spring-aop:jar:4.3.11.RELEASE:provided - omitted for duplicate)
[INFO] |  |  |  +- (org.springframework:spring-beans:jar:4.3.11.RELEASE:provided - omitted for duplicate)
[INFO] |  |  |  +- (org.springframework:spring-context:jar:4.3.11.RELEASE:provided - omitted for duplicate)
[INFO] |  |  |  +- (org.springframework:spring-core:jar:4.3.11.RELEASE:provided - omitted for duplicate)
[INFO] |  |  |  +- (org.springframework:spring-expression:jar:4.3.11.RELEASE:provided - omitted for duplicate)
[INFO] |  |  |  \- (org.springframework:spring-web:jar:4.3.11.RELEASE:provided - omitted for duplicate)
[INFO] |  |  +- org.springframework.data:spring-data-redis:jar:1.7.0.RELEASE:provided
[INFO] |  |  |  +- org.springframework.data:spring-data-keyvalue:jar:1.1.0.RELEASE:provided
[INFO] |  |  |  |  +- org.springframework.data:spring-data-commons:jar:1.12.0.RELEASE:provided
[INFO] |  |  |  |  |  +- (org.springframework:spring-core:jar:4.2.5.RELEASE:provided - omitted for conflict with 4.3.11.RELEASE)
[INFO] |  |  |  |  |  \- (org.springframework:spring-beans:jar:4.2.5.RELEASE:provided - omitted for conflict with 4.3.11.RELEASE)
[INFO] |  |  |  |  +- (org.springframework:spring-context:jar:4.2.5.RELEASE:provided - omitted for conflict with 4.3.11.RELEASE)
[INFO] |  |  |  |  \- (org.springframework:spring-tx:jar:4.2.5.RELEASE:provided - omitted for conflict with 4.3.11.RELEASE)
[INFO] |  |  |  +- (org.springframework:spring-tx:jar:4.2.5.RELEASE:provided - omitted for conflict with 4.3.11.RELEASE)
[INFO] |  |  |  +- org.springframework:spring-oxm:jar:4.2.5.RELEASE:provided
[INFO] |  |  |  |  +- (org.springframework:spring-beans:jar:4.2.5.RELEASE:provided - omitted for conflict with 4.3.11.RELEASE)
[INFO] |  |  |  |  \- (org.springframework:spring-core:jar:4.2.5.RELEASE:provided - omitted for conflict with 4.3.11.RELEASE)
[INFO] |  |  |  +- (org.springframework:spring-aop:jar:4.2.5.RELEASE:provided - omitted for conflict with 4.3.11.RELEASE)
[INFO] |  |  |  \- (org.springframework:spring-context-support:jar:4.2.5.RELEASE:provided - omitted for conflict with 4.3.11.RELEASE)
[INFO] |  |  +- org.springframework.security:spring-security-web:jar:4.0.4.RELEASE:provided
[INFO] |  |  |  +- org.springframework.security:spring-security-core:jar:4.0.4.RELEASE:provided
[INFO] |  |  |  |  +- (org.springframework:spring-aop:jar:4.2.5.RELEASE:provided - omitted for conflict with 4.3.11.RELEASE)
[INFO] |  |  |  |  +- (org.springframework:spring-beans:jar:4.2.5.RELEASE:provided - omitted for conflict with 4.3.11.RELEASE)
[INFO] |  |  |  |  +- (org.springframework:spring-context:jar:4.2.5.RELEASE:provided - omitted for conflict with 4.3.11.RELEASE)
[INFO] |  |  |  |  +- (org.springframework:spring-core:jar:4.2.5.RELEASE:provided - omitted for conflict with 4.3.11.RELEASE)
[INFO] |  |  |  |  \- (org.springframework:spring-expression:jar:4.2.5.RELEASE:provided - omitted for conflict with 4.3.11.RELEASE)
[INFO] |  |  |  +- (org.springframework:spring-beans:jar:4.2.5.RELEASE:provided - omitted for conflict with 4.3.11.RELEASE)
[INFO] |  |  |  +- (org.springframework:spring-context:jar:4.2.5.RELEASE:provided - omitted for conflict with 4.3.11.RELEASE)
[INFO] |  |  |  +- (org.springframework:spring-core:jar:4.2.5.RELEASE:provided - omitted for conflict with 4.3.11.RELEASE)
[INFO] |  |  |  +- (org.springframework:spring-expression:jar:4.2.5.RELEASE:provided - omitted for conflict with 4.3.11.RELEASE)
[INFO] |  |  |  \- (org.springframework:spring-web:jar:4.2.5.RELEASE:provided - omitted for conflict with 4.3.11.RELEASE)
[INFO] |  |  +- org.springframework.security:spring-security-config:jar:4.0.4.RELEASE:provided
[INFO] |  |  |  +- (org.springframework:spring-aop:jar:4.2.5.RELEASE:provided - omitted for conflict with 4.3.11.RELEASE)
[INFO] |  |  |  +- (org.springframework:spring-beans:jar:4.2.5.RELEASE:provided - omitted for conflict with 4.3.11.RELEASE)
[INFO] |  |  |  +- (org.springframework:spring-context:jar:4.2.5.RELEASE:provided - omitted for conflict with 4.3.11.RELEASE)
[INFO] |  |  |  \- (org.springframework:spring-core:jar:4.2.5.RELEASE:provided - omitted for conflict with 4.3.11.RELEASE)
[INFO] |  |  +- org.springframework.security:spring-security-cas:jar:4.0.4.RELEASE:provided
[INFO] |  |  |  +- (org.springframework:spring-beans:jar:4.2.5.RELEASE:provided - omitted for conflict with 4.3.11.RELEASE)
[INFO] |  |  |  +- (org.springframework:spring-context:jar:4.2.5.RELEASE:provided - omitted for conflict with 4.3.11.RELEASE)
[INFO] |  |  |  +- (org.springframework:spring-core:jar:4.2.5.RELEASE:provided - omitted for conflict with 4.3.11.RELEASE)
[INFO] |  |  |  \- (org.springframework:spring-web:jar:4.2.5.RELEASE:provided - omitted for conflict with 4.3.11.RELEASE)
[INFO] |  |  +- org.springframework.security.oauth:spring-security-oauth2:jar:2.0.7.RELEASE:provided
[INFO] |  |  |  +- (org.springframework:spring-beans:jar:4.0.9.RELEASE:provided - omitted for conflict with 4.3.11.RELEASE)
[INFO] |  |  |  +- (org.springframework:spring-core:jar:4.0.9.RELEASE:provided - omitted for conflict with 4.3.11.RELEASE)
[INFO] |  |  |  +- (org.springframework:spring-context:jar:4.0.9.RELEASE:provided - omitted for conflict with 4.3.11.RELEASE)
[INFO] |  |  |  \- (org.springframework:spring-webmvc:jar:4.0.9.RELEASE:provided - omitted for conflict with 4.3.11.RELEASE)
[INFO] |  |  +- org.springframework.security:spring-security-ldap:jar:4.0.4.RELEASE:provided
[INFO] |  |  |  +- (org.springframework:spring-beans:jar:4.2.5.RELEASE:provided - omitted for conflict with 4.3.11.RELEASE)
[INFO] |  |  |  +- (org.springframework:spring-context:jar:4.2.5.RELEASE:provided - omitted for conflict with 4.3.11.RELEASE)
[INFO] |  |  |  +- (org.springframework:spring-core:jar:4.2.5.RELEASE:provided - omitted for conflict with 4.3.11.RELEASE)
[INFO] |  |  |  \- (org.springframework:spring-tx:jar:4.2.5.RELEASE:provided - omitted for conflict with 4.3.11.RELEASE)
[INFO] |  |  +- com.ryantenney.metrics:metrics-spring:jar:3.1.3:provided
[INFO] |  |  |  \- (org.springframework:spring-context-support:jar:4.1.6.RELEASE:provided - omitted for conflict with 4.3.11.RELEASE)
[INFO] |  |  +- org.springframework.amqp:spring-rabbit:jar:1.7.1.RELEASE:provided
[INFO] |  |  |  +- (org.springframework:spring-web:jar:4.3.7.RELEASE:provided - omitted for conflict with 4.3.11.RELEASE)
[INFO] |  |  |  +- (org.springframework:spring-messaging:jar:4.3.7.RELEASE:provided - omitted for conflict with 4.3.11.RELEASE)
[INFO] |  |  |  +- org.springframework.amqp:spring-amqp:jar:1.7.1.RELEASE:provided
[INFO] |  |  |  |  \- (org.springframework:spring-core:jar:4.3.7.RELEASE:provided - omitted for conflict with 4.3.11.RELEASE)
[INFO] |  |  |  +- (org.springframework:spring-tx:jar:4.3.7.RELEASE:provided - omitted for conflict with 4.3.11.RELEASE)
[INFO] |  |  |  \- (org.springframework:spring-context:jar:4.3.7.RELEASE:provided - omitted for conflict with 4.3.11.RELEASE)
[INFO] |  |  +- org.springframework:spring-websocket:jar:4.3.11.RELEASE:provided
[INFO] |  |  |  +- (org.springframework:spring-context:jar:4.3.11.RELEASE:provided - omitted for duplicate)
[INFO] |  |  |  +- (org.springframework:spring-core:jar:4.3.11.RELEASE:provided - omitted for duplicate)
[INFO] |  |  |  \- (org.springframework:spring-web:jar:4.3.11.RELEASE:provided - omitted for duplicate)
[INFO] |  |  \- org.springframework:spring-messaging:jar:4.3.11.RELEASE:provided
[INFO] |  |     +- (org.springframework:spring-beans:jar:4.3.11.RELEASE:provided - omitted for duplicate)
[INFO] |  |     +- (org.springframework:spring-context:jar:4.3.11.RELEASE:provided - omitted for duplicate)
[INFO] |  |     \- (org.springframework:spring-core:jar:4.3.11.RELEASE:provided - omitted for duplicate)
[INFO] |  +- com.hand:hap-workflow:jar:classes:3.5.4-RELEASE:provided
[INFO] |  |  +- org.activiti:activiti-spring:jar:6.0.0:provided
[INFO] |  |  |  +- (org.springframework:spring-context:jar:4.2.5.RELEASE:provided - omitted for conflict with 4.3.11.RELEASE)
[INFO] |  |  |  \- (org.springframework:spring-jdbc:jar:4.2.5.RELEASE:provided - omitted for conflict with 4.3.11.RELEASE)
[INFO] |  |  \- org.activiti:activiti-rest:jar:6.0.0:provided
[INFO] |  |     +- (org.springframework:spring-context:jar:4.2.5.RELEASE:provided - omitted for conflict with 4.3.11.RELEASE)
[INFO] |  |     \- (org.springframework:spring-webmvc:jar:4.2.5.RELEASE:provided - omitted for conflict with 4.3.11.RELEASE)
[INFO] |  \- com.hand:hap-report:jar:classes:3.5.4-RELEASE:provided
[INFO] |     \- com.bstek.ureport:ureport2-console:jar:2.2:provided
[INFO] |        \- com.bstek.ureport:ureport2-core:jar:2.2:provided
[INFO] |           +- (org.springframework:spring-web:jar:4.3.11.RELEASE:provided - omitted for duplicate)
[INFO] |           \- (org.springframework:spring-jdbc:jar:4.3.11.RELEASE:provided - omitted for duplicate)
[INFO] \- hscs:core:jar:classes:2.2.1-SNAPSHOT:provided
[INFO]    \- org.springframework.kafka:spring-kafka:jar:1.3.0.RELEASE:provided
[INFO]       +- (org.springframework:spring-messaging:jar:4.3.11.RELEASE:provided - omitted for duplicate)
[INFO]       +- org.springframework:spring-tx:jar:4.3.11.RELEASE:provided
[INFO]       |  +- (org.springframework:spring-beans:jar:4.3.11.RELEASE:provided - omitted for duplicate)
[INFO]       |  \- (org.springframework:spring-core:jar:4.3.11.RELEASE:provided - omitted for duplicate)
[INFO]       \- org.springframework.retry:spring-retry:jar:1.2.0.RELEASE:provided
[INFO]          \- (org.springframework:spring-core:jar:4.3.3.RELEASE:provided - omitted for conflict with 4.3.11.RELEASE)
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for FishParent 1.0-SNAPSHOT:
[INFO] 
[INFO] FishParent ......................................... SUCCESS [  0.922 s]
[INFO] core-db ............................................ SUCCESS [  0.539 s]
[INFO] core ............................................... SUCCESS [  4.020 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  5.780 s
[INFO] Finished at: 2019-03-21T15:38:44+08:00
[INFO] ------------------------------------------------------------------------
xujiaqingdeMacBook-Pro:mos jaycee$ 

实际上,对于omitted for duplicate的提示,我们可以不用去解决,只是提示了该包的重复定义。在实际情况上,更多的是根据就近原则引用了一个低版本的jar包,这样本身高版本的Jar包包含的方法,在低版本却没有,导致项目在调用时,出现了“方法找不到”类似的异常信息。

以上为个人经验,希望能给大家一个参考,也希望大家多多支持编程网。

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

关于Maven依赖冲突解决之exclusions

下载Word文档到电脑,方便收藏和打印~

下载Word文档

猜你喜欢

如何解决Maven依赖冲突

今天小编给大家分享的是如何解决Maven依赖冲突,相信很多人都不太了解,为了让大家更加了解,所以给大家总结了以下内容,一起往下看吧。一定会有所收获的哦。目录背景处理回顾背景在项目中screw-core依赖时发生了冲突,控制台指出是log4j
2023-07-06

解决Maven依赖冲突的方法

本文主要介绍了解决Maven依赖冲突的方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
2023-05-20

maven冲突依赖问题如何解决

Maven冲突依赖问题可以通过以下方法解决:使用`mvn dependency:tree`命令查看项目的依赖树,找到冲突的依赖项。使用``标签排除冲突的依赖项。在项目的pom.xml文件中,找到引起冲突的依赖项,然后添加``标签来排除其中的
2023-10-27

maven多版本依赖冲突问题怎么解决

Maven的多版本依赖冲突问题可以通过以下几种方式解决:1. 排除依赖:在项目的pom.xml文件中,可以使用``标签排除某个依赖的传递性依赖。例如:```xmlcom.exampleexample1.0.0com.exampleconfl
2023-09-23

maven依赖冲突的原因及解决方法是什么

Maven依赖冲突的原因可能是由于以下几个因素:1. 版本不匹配:当项目中存在多个依赖项,并且这些依赖项使用了不同的版本时,可能会导致依赖冲突。2. 传递性依赖:当一个依赖项依赖于另一个依赖项,并且这两个依赖项的版本不兼容时,也可能会引发依
2023-09-23

gradle依赖冲突问题怎么解决

在Gradle中,依赖冲突通常是由于不同的依赖项引入了相同的库的不同版本造成的。以下是一些解决依赖冲突问题的方法:1. 使用`gradle dependencies`命令查看项目中的依赖关系,找到冲突的依赖项。2. 在`build.grad
2023-10-11

Linux中软件包依赖冲突解决

在Linux中,软件包依赖冲突是指在安装、更新或删除软件包时,由于软件包之间的相互依赖关系而导致的问题使用包管理器:大多数Linux发行版都有自己的包管理器,如Ubuntu的APT,Fedora的DNF,Arch Linux的pacman等
Linux中软件包依赖冲突解决
2024-09-24

linux安装依赖库冲突如何解决

在Linux上,解决依赖库冲突的方法包括以下几种:1. 使用包管理器解决冲突:大多数Linux发行版都提供了自己的包管理器,如apt、yum、dnf等。使用包管理器可以自动解决依赖关系并安装正确的版本。例如,对于Ubuntu系统,可以使用a
2023-09-22

java怎么解决依赖版本冲突问题

在Java中解决依赖版本冲突问题有以下几种方法:更新依赖版本:可以尝试更新冲突的依赖版本,看是否有新版本解决了冲突问题。可以通过查看依赖的官方文档、GitHub仓库或Maven仓库来了解最新的版本信息。排除冲突依赖:可以使用Maven或Gr
2023-10-27

编程热搜

  • Python 学习之路 - Python
    一、安装Python34Windows在Python官网(https://www.python.org/downloads/)下载安装包并安装。Python的默认安装路径是:C:\Python34配置环境变量:【右键计算机】--》【属性】-
    Python 学习之路 - Python
  • chatgpt的中文全称是什么
    chatgpt的中文全称是生成型预训练变换模型。ChatGPT是什么ChatGPT是美国人工智能研究实验室OpenAI开发的一种全新聊天机器人模型,它能够通过学习和理解人类的语言来进行对话,还能根据聊天的上下文进行互动,并协助人类完成一系列
    chatgpt的中文全称是什么
  • C/C++中extern函数使用详解
  • C/C++可变参数的使用
    可变参数的使用方法远远不止以下几种,不过在C,C++中使用可变参数时要小心,在使用printf()等函数时传入的参数个数一定不能比前面的格式化字符串中的’%’符号个数少,否则会产生访问越界,运气不好的话还会导致程序崩溃
    C/C++可变参数的使用
  • css样式文件该放在哪里
  • php中数组下标必须是连续的吗
  • Python 3 教程
    Python 3 教程 Python 的 3.0 版本,常被称为 Python 3000,或简称 Py3k。相对于 Python 的早期版本,这是一个较大的升级。为了不带入过多的累赘,Python 3.0 在设计的时候没有考虑向下兼容。 Python
    Python 3 教程
  • Python pip包管理
    一、前言    在Python中, 安装第三方模块是通过 setuptools 这个工具完成的。 Python有两个封装了 setuptools的包管理工具: easy_install  和  pip , 目前官方推荐使用 pip。    
    Python pip包管理
  • ubuntu如何重新编译内核
  • 改善Java代码之慎用java动态编译

目录