关于Maven依赖冲突解决之exclusions

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

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

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

(0)

相关推荐

  • maven坐标Dependencies和Exclusions的使用

    目录 1.概念介绍 2.Dependencies (1)当一个项目A依赖另一个项目B时 (2)配置可选依赖的原因 (3)示例 3.Exclusions (1)当一个项目A依赖项目B (2)示例 4.maven的依赖调解有两大原则 5.maven的归类依赖 聊下maven Exclusions标签 1.概念介绍 Dependencies:是可选依赖(Optional Dependencies) Exclusions:是依赖排除(Dependency Exclusions) 2.Dependenci

  • 聊聊maven的pom.xml中的exclusions标签的作用

    maven pom.xml的exclusions标签作用 项目中的例子 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> <exclusions> <exclusion> <groupId>org.springframework.boot</groupI

  • 详解maven依赖冲突以及解决方法

    什么是依赖冲突 依赖冲突是指项目依赖的某一个jar包,有多个不同的版本,因而造成类包版本冲突 依赖冲突的原因 依赖冲突很经常是类包之间的间接依赖引起的.每个显式声明的类包都会依赖于一些其它的隐式类包,这些隐式的类包会被maven间接引入进来,从而造成类包冲突 如何解决依赖冲突 首先查看产生依赖冲突的类jar,其次找出我们不想要的依赖类jar,手工将其排除在外就可以了.具体执行步骤如下 1.查看依赖冲突 a.通过dependency:tree是命令来检查版本冲突 mvn -Dverbose dep

  • 深入理解Maven的坐标与依赖

    在前边两节中,我们学习了Maven的基本概念以及何为Maven仓库,并且如何配置settings.xml文件等相关知识点.Maven的主要作用是可以帮助我们自动下载在pom.xml中配置添加的依赖.那么在本节中,我们将学习如何引入依赖. 知识点包括: Maven的坐标,Maven的依赖配置,依赖范围,传递性依赖,依赖调解,可选依赖,排除依赖,归类依赖和优化依赖 Maven的坐标 Maven的仓库中拥有着无数的构件,每一个构件都是一个jar或者war等文件,如果没有坐标,那么我们将无法唯一标识该构

  • 关于Maven依赖冲突解决之exclusions

    目录 Maven依赖冲突解决之exclusions 1. 背景 2. 解决方式 场景 解决方式 Maven解决依赖冲突总结 实例分析 解决办法 命令分析 小试牛刀 Maven依赖冲突解决之exclusions 1. 背景 作为java生态下开发者,往往需要使用大量线程的第三方库,一般都是以jar包形式存在. maven作为事实上主流的jar包依赖管理工具,Idea和Eclipse都支持创建maven工程来管理jar包依赖. 使用maven进行jar包依赖管理时,maven会自行管理jar包及其依

  • 使用idea解决maven依赖冲突的问题

    前言:我们进行用maven 开发组件的时候,经常会遇到一种情况,我们添加一些maven依赖后,经常会出现本地原本正常的代码编译不过去 下面我们就将这种问题的解决思路和解决方案逐步讲解 记录报错的那几个类 将刚才添加的maven依赖都还原找到刚才报错的类的jar包的版本号 例如我们的文件fastjson-1.2.58 还原刚才加入的maven依赖在刚才编译报错的maven 模块上构建maven依赖体系 结果如下图所示 6.在构建结果中按ctrl+F 7.输入报错的jar包的名字 8.选中一个点进去

  • Android Studio Gradle依赖冲突解决方法

    前言 本文主要给大家介绍了Android Studio Gradle依赖冲突解决的相关内容,分享出来供大家参考学习,下面话不多说了,来一起看看详细的介绍吧 1. 查看依赖树 ./gradlew dependencies 2. 解决依赖冲突 一旦在构建中存在依赖冲突,开发人员需要决定哪个版本的库最终包含在构建中,有许多解决冲突的方法. 1. 逐个排除 compile('junit:junit:4.12'){ exclude group : 'org.hamcrest',module:'hamcre

  • 详解Gradle依赖冲突解决方式

    问题 在Android开发中,相信遇到关于版本依赖的问题的同学有不少.虽然Android Studio一般都会自动帮我们去重,但是有时候去重失败了还是需要手动处理.在这里总结下自己长期遇到的各类问题的解决方式. 为了方便看效果,我们改下gradle解决策略为有版本冲突时自动失败,如下: configurations.all { resolutionStrategy { failOnVersionConflict() } } 当我们同时依赖不同版本rxjava时编译会报错如下: 解决方案 1.统一

  • springboot依赖冲突问题及解决过程

    项目场景: 新搭了一个springboot 2.3.7.RELASE的框架,在集成mysql,tkMapper,mybatis的过程中,启动报错. 问题描述: 提示各种依赖的错误 通过idea的功能解决冲突依赖,尝试了多次,也不行 还尝试过删除可能意外引入的jar: 原因分析: 在之前搭的一个分布式项目里面有这些基础的配置,依赖按照版本拿过来一个个添加,尝试,依然不行. 在旧的项目可以,在这里就不行. 把springboot版本改成和旧项目一样,也不可以. 解决方案: 最后,把代码全部删掉(因为

  • 使用Maven Helper解决Maven插件冲突的方法

    1.何为依赖冲突 Maven是个很好用的依赖管理工具,但是再好的东西也不是完美的.Maven的依赖机制会导致Jar包的冲突.举个例子,现在你的项目中,使用了两个Jar包,分别是A和B.现在A需要依赖另一个Jar包C,B也需要依赖C.但是A依赖的C的版本是1.0,B依赖的C的版本是2.0.这时候,Maven会将这1.0的C和2.0的C都下载到你的项目中,这样你的项目中就存在了不同版本的C,这时Maven会依据依赖路径最短优先原则,来决定使用哪个版本的Jar包,而另一个无用的Jar包则未被使用,这就

  • 解决Mybatis-plus和pagehelper依赖冲突的方法示例

    简介 MyBatis-Plus(简称 MP)是一个 MyBatis 的增强工具,在 MyBatis 的基础上只做增强不做改变,为简化开发.提高效率而生. 启动即会自动注入基本 CURD,性能基本无损耗,直接面向对象操作 Mybati-plus本身自带分页功能,但是我个人一直是使用pagehelper进行分页,所以在pom中添加了pagehelper依赖,但是运行项目后发现jar包冲突,面对冲突我们应该怎么解决它呢,看完如下内容便可轻松解决 先看依赖 <!-- mbatis-plus --> &

  • 浅谈Maven包冲突的原理及解决方法

    1.概述 Apache Maven ,是一个软件(特别是Java软件)项目管理及自动构建工具.在没有Maven的上古年代,项目中引入jar包需要手动下载一个个的去下载,但是随着代码数量的增加,引入的jar包数量自然会增加,随之而来的就是jar包冲突的问题了. 2.产生jar包冲突的原因 众所周知,一个项目中不能存在两个全限定类名一致的Class类,并且jar包的本质就是打包好的Class类文件,例如: 将 junit-jupiter-api-5.6.2.jar 文件解压后, 可以得到多个Clas

  • IDEA解决maven包冲突easypoi NoClassDefFoundError的问题

    在平常工作中我们经常会遇到maven引用的jar包冲突的事情,这时候我们就需要找出冲突的包,并将低版本或者缺少某些方法的jar给剔除掉.这个时候使用idea自带的maven依赖树就很好解决这样的问题. 包冲突显现出来的问题有:某些类找不到. 原因:工程中引入了一个需要的依赖,但工程中其他依赖的包内部也可能会有相同的依赖,如果版本不同maven可能取了一个低的版本,然后可能造成某个类找不到. 比如: 在工程中引入了easypoi jar,要使用Excel导出功能. <dependency> &l

随机推荐