maven implicit dependencies cause packet conflict resolution

  • 2020-05-26 08:36:46
  • OfStack

Packet collision

1. When using maven to manage projects, you may encounter package conflicts, such as: log4j-over-slf4j. jar and slf4j4j12.jar, when the two packages are shipped at the same time, there will be problems.

2. This conflict may be caused by explicit or implicit dependencies.

Explicit dependencies can be obtained directly from the pom.xml file < dependency > You see references to two conflicting packages in.

Implicit dependencies in pom.xml < dependency > Cannot see the conflicting package, but instead by < dependency > Introduced package introduced indirectly.

To solve

Identify which dependencies are indirectly introduced into the package. Use mvn dependency:tree to view the entire project's dependency tree, where you can see all dependencies, including indirect dependencies.
The results are similar to the following:


[INFO] +- junit:junit:jar:4.12:test
[INFO] | \- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] +- org.apache.storm:storm-core:jar:1.0.2:provided
[INFO] | +- com.esotericsoftware:kryo:jar:3.0.3:compile
[INFO] | | \- com.esotericsoftware:minlog:jar:1.3.0:compile
[INFO] | +- org.clojure:clojure:jar:1.7.0:provided
[INFO] | +- com.lmax:disruptor:jar:3.3.2:provided
[INFO] | +- org.apache.logging.log4j:log4j-api:jar:2.1:provided
[INFO] | +- org.apache.logging.log4j:log4j-core:jar:2.1:provided
[INFO] | +- org.apache.logging.log4j:log4j-slf4j-impl:jar:2.1:provided
[INFO] | +- org.slf4j:log4j-over-slf4j:jar:1.6.6:provided
[INFO] | +- javax.servlet:servlet-api:jar:2.5:provided
[INFO] | \- org.slf4j:slf4j-api:jar:1.7.7:compile
[INFO] +- com.aaa.khala:aaa-khala-insight-sdk-transfer-api:jar:1.0.0-SNAPSHOT:compile
[INFO] | \- com.aaa.khala:aaa-khala-common:jar:1.0.0-SNAPSHOT:compile
[INFO] |   +- javax.mail:javax.mail-api:jar:1.5.5:compile
[INFO] |   +- cglib:cglib:jar:2.2.2:compile
[INFO] |   +- org.aspectj:aspectjrt:jar:1.7.4:compile
[INFO] |   +- org.aspectj:aspectjweaver:jar:1.7.4:runtime
[INFO] |   +- org.javassist:javassist:jar:3.20.0-GA:compile
[INFO] |   +- log4j:log4j:jar:1.2.17:compile
[INFO] |   +- org.slf4j:slf4j-log4j12:jar:1.7.7:compile
[INFO] |   +- dom4j:dom4j:jar:1.6.1:compile
[INFO] |   +- jaxen:jaxen:jar:1.1.6:compile
[INFO] |   +- commons-collections:commons-collections:jar:3.2.1:compile
[INFO] |   +- commons-codec:commons-codec:jar:1.9:compile
[INFO] |   +- commons-beanutils:commons-beanutils:jar:1.9.2:compile
[INFO] |   +- org.apache.commons:commons-compress:jar:1.6:compile
[INFO] |   | \- org.tukaani:xz:jar:1.4:compile

Check the dependency corresponding to the conflict package in pom.xml < dependency > The package will not be introduced if the configuration is excluded, for example:


<dependency>
  <groupId>com.aaa.khala</groupId>
  <artifactId>aaa-khala-insight-sdk-transfer-api</artifactId>
  <version>1.0.0-SNAPSHOT</version>
  <exclusions> 
    <exclusion> 
      <groupId>org.slf4j</groupId> 
      <artifactId>slf4j-log4j12</artifactId> 
    </exclusion> 
  </exclusions>
</dependency>  

Thank you for reading, I hope to help you, thank you for your support of this site!


Related articles: