广告
返回顶部
首页 > 资讯 > 后端开发 > Python >关于Maven依赖冲突解决之exclusions
  • 169
分享到

关于Maven依赖冲突解决之exclusions

2024-04-02 19:04:59 169人浏览 八月长安

Python 官方文档:入门教程 => 点击学习

摘要

目录Maven依赖冲突解决之exclusions1. 背景2. 解决方式场景解决方式Maven解决依赖冲突总结实例分析解决办法命令分析小试牛刀Maven依赖冲突解决之exclusio

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包包含的方法,在低版本却没有,导致项目在调用时,出现了“方法找不到”类似的异常信息。

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

--结束END--

本文标题: 关于Maven依赖冲突解决之exclusions

本文链接: https://www.lsjlt.com/news/160414.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

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

下载Word文档
猜你喜欢
  • 关于Maven依赖冲突解决之exclusions
    目录Maven依赖冲突解决之exclusions1. 背景2. 解决方式场景解决方式Maven解决依赖冲突总结实例分析解决办法命令分析小试牛刀Maven依赖冲突解决之exclusio...
    99+
    2022-11-12
  • 如何解决Maven依赖冲突
    今天小编给大家分享的是如何解决Maven依赖冲突,相信很多人都不太了解,为了让大家更加了解,所以给大家总结了以下内容,一起往下看吧。一定会有所收获的哦。目录背景处理回顾背景在项目中screw-core依赖时发生了冲突,控制台指出是log4j...
    99+
    2023-07-06
  • 解决Maven依赖冲突的方法
    目录背景处理回顾背景 在项目中screw-core依赖时发生了冲突,控制台指出是log4j产生的依赖冲突,导致程序报错无法运行,是一个典型的maven依赖冲突,基于这个问题进行 处理...
    99+
    2023-05-20
    Maven依赖冲突
  • maven冲突依赖问题如何解决
    Maven冲突依赖问题可以通过以下方法解决: 使用`mvn dependency:tree`命令查看项目的依赖树,找到冲突的依赖...
    99+
    2023-10-27
    maven
  • 如何定位、解决maven依赖冲突问题
    目录 1.依赖冲突的原因 2.复现一个依赖冲突场景 3.如何定位依赖冲突 3.1.maven show dependencies 3.2.maven helper 4.依赖路径最短优先原则 1.依赖冲突的原因 如果maven项目中,A依...
    99+
    2023-09-03
    算法 linux 前端 原力计划
  • maven多版本依赖冲突问题怎么解决
    Maven的多版本依赖冲突问题可以通过以下几种方式解决:1. 排除依赖:在项目的pom.xml文件中,可以使用``标签排除某个依赖的...
    99+
    2023-09-23
    maven
  • 关于Springboot+gateway整合依赖并处理依赖冲突问题
    正文 spring boot版本和spring cloud版本 框架版本SpringBoot2.3.12.RELEASESpringCloudHoxton.SR1 pom依赖 &l...
    99+
    2022-11-12
  • maven依赖冲突的原因及解决方法是什么
    Maven依赖冲突的原因可能是由于以下几个因素:1. 版本不匹配:当项目中存在多个依赖项,并且这些依赖项使用了不同的版本时,可能会导...
    99+
    2023-09-23
    maven
  • gradle依赖冲突问题怎么解决
    在Gradle中,依赖冲突通常是由于不同的依赖项引入了相同的库的不同版本造成的。以下是一些解决依赖冲突问题的方法:1. 使用`gra...
    99+
    2023-10-11
    gradle
  • springboot依赖冲突问题及解决过程
    项目场景:  新搭了一个springboot 2.3.7.RELASE的框架,在集成mysql,tkMapper,mybatis的过程中,启动报错。 问题描述: 提示各种依...
    99+
    2022-11-12
  • linux安装依赖库冲突如何解决
    在Linux上,解决依赖库冲突的方法包括以下几种:1. 使用包管理器解决冲突:大多数Linux发行版都提供了自己的包管理器,如apt...
    99+
    2023-09-22
    linux
  • java怎么解决依赖版本冲突问题
    在Java中解决依赖版本冲突问题有以下几种方法: 更新依赖版本:可以尝试更新冲突的依赖版本,看是否有新版本解决了冲突问题。可以通...
    99+
    2023-10-27
    java
  • Mybatis-plus与Mybatis依赖冲突问题解决方法
    错误描述 An attempt was made to call a method that does not exist. The attempt was made from t...
    99+
    2022-11-12
  • 解决Mybatis-plus和pagehelper依赖冲突的方法示例
    简介 MyBatis-Plus(简称 MP)是一个 MyBatis 的增强工具,在 MyBatis 的基础上只做增强不做改变,为简化开发、提高效率而生。 启动即会...
    99+
    2022-11-12
  • 基于Maven导入pom依赖很慢的解决方案
    目录Maven导入pom依赖很慢的问题原因第一步:找到maven的安装路径 ,修改settings.xml第二步:重启idea 导入依赖发现会很快Maven导入pom依赖很慢的问题 ...
    99+
    2022-11-12
  • 关于spring循环依赖问题及解决方案
    目录一、三种循环依赖的情况比如几个Bean之间的互相引用 甚至自己“循环”依赖自己二、解决方案如何获取依赖三、解决循环依赖必须要三级缓存吗结论四、无...
    99+
    2022-11-13
  • 关于Spring源码是如何解决Bean的循环依赖
    目录两个单例testA testB 互相依赖的实例化过程Spring容器创建单例“testA”beanSpring容器创建单例“testB”bean源码中的实现方式首先了解一下创建B...
    99+
    2022-11-12
  • 【Flink】关于jvm元空间溢出,mysql binlog冲突的问题解决
    问题一:7张表是同一个mysql中的,我们进行增量同步时分别用不同的flink任务读取,造成mysql server-id冲突问题,如下: Caused by: io.debezium.Debe...
    99+
    2023-10-10
    flink jvm mysql
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作