Scala SBT Assembly cannot merge due to de-duplication error in StaticLoggerBinder.class

后端 未结 2 561
再見小時候
再見小時候 2021-02-08 12:48

My problem is I can no longer use the sbt-assembly plugin because some kind of dependency merge problem creeped in, between a couple people working on this project.

The

2条回答
  •  梦谈多话
    2021-02-08 13:34

    Previous answer gives all the required feedback, but does not actually give any solution or steps to try out.

    My error:

    [error] (project/*:assembly) deduplicate: different file contents found in the following:
    [error] /home/user/.ivy2/cache/ch.qos.logback/logback-classic/jars/logback-classic-1.2.3.jar:org/slf4j/impl/StaticLoggerBinder.class
    [error] /home/user/.ivy2/cache/org.slf4j/slf4j-log4j12/jars/slf4j-log4j12-1.7.10.jar:org/slf4j/impl/StaticLoggerBinder.class
    [error] deduplicate: different file contents found in the following:
    [error] /home/user/.ivy2/cache/ch.qos.logback/logback-classic/jars/logback-classic-1.2.3.jar:org/slf4j/impl/StaticMDCBinder.class
    [error] /home/user/.ivy2/cache/org.slf4j/slf4j-log4j12/jars/slf4j-log4j12-1.7.10.jar:org/slf4j/impl/StaticMDCBinder.class
    [error] deduplicate: different file contents found in the following:
    [error] /home/user/.ivy2/cache/ch.qos.logback/logback-classic/jars/logback-classic-1.2.3.jar:org/slf4j/impl/StaticMarkerBinder.class
    [error] /home/user/.ivy2/cache/org.slf4j/slf4j-log4j12/jars/slf4j-log4j12-1.7.10.jar:org/slf4j/impl/StaticMarkerBinder.class
    

    Recommended way

    track down conflicting dependency. For example, I do not want those classes:

    org.slf4j/slf4j-log4j12/jars/slf4j-log4j12-1.7.10.jar:org/slf4j/impl/StaticLoggerBinder.class
    org.slf4j/slf4j-log4j12/jars/slf4j-log4j12-1.7.10.jar:org/slf4j/impl/StaticMDCBinder.class
    org.slf4j/slf4j-log4j12/jars/slf4j-log4j12-1.7.10.jar:org/slf4j/impl/StaticMarkerBinder.class
    

    Call sbt (and make sure to use sbt-dependency-graph plugin):

    whatDependsOn org.slf4j slf4j-log4j12 1.7.10
    

    Returns a list:

    [info] org.slf4j:slf4j-log4j12:1.7.10
    [info]   +-org.apache.hadoop:hadoop-auth:2.8.0
    [info]   | +-org.apache.hadoop:hadoop-common:2.8.0
    [info]   |   +-com.github.atais:test_2.11:0.0.3 [S]
    [info]   |   
    [info]   +-org.apache.hadoop:hadoop-common:2.8.0
    [info]   | +com.github.atais:test_2.11:0.0.3 [S]
    [info]   | 
    [info]   +-org.apache.zookeeper:zookeeper:3.4.6
    [info]     +-org.apache.curator:curator-client:2.7.1
    [info]     | +-org.apache.curator:curator-framework:2.7.1
    [info]     | | +-org.apache.curator:curator-recipes:2.7.1
    [info]     | | | +-org.apache.hadoop:hadoop-common:2.8.0
    [info]     | | |   +-com.github.atais:test_2.11:0.0.3 [S]
    [info]     | | |   
    [info]     | | +-org.apache.hadoop:hadoop-auth:2.8.0
    [info]     | |   +-org.apache.hadoop:hadoop-common:2.8.0
    [info]     | |     +-com.github.atais:test_2.11:0.0.3 [S]
    [info]     | |     
    [info]     | +-org.apache.hadoop:hadoop-common:2.8.0
    [info]     |   +-com.github.atais:test_2.11:0.0.3 [S]
    [info]     |   
    [info]     +-org.apache.curator:curator-framework:2.7.1
    [info]     | +-org.apache.curator:curator-recipes:2.7.1
    [info]     | | +-org.apache.hadoop:hadoop-common:2.8.0
    [info]     | |   +-com.github.atais:test_2.11:0.0.3 [S]
    [info]     | |   
    [info]     | +-org.apache.hadoop:hadoop-auth:2.8.0
    [info]     |   +-org.apache.hadoop:hadoop-common:2.8.0
    [info]     |     +-com.github.atais:test_2.11:0.0.3 [S]
    [info]     |     
    [info]     +-org.apache.curator:curator-recipes:2.7.1
    [info]     | +-org.apache.hadoop:hadoop-common:2.8.0
    [info]     |   +-com.github.atais:test_2.11:0.0.3 [S]
    [info]     |   
    [info]     +-org.apache.hadoop:hadoop-auth:2.8.0
    [info]     | +-org.apache.hadoop:hadoop-common:2.8.0
    [info]     |   +-com.github.atais:test_2.11:0.0.3 [S]
    [info]     |   
    [info]     +-org.apache.hadoop:hadoop-common:2.8.0
    [info]       +-com.github.atais:test_2.11:0.0.3 [S]
    

    I need to track down hadoop-common dependency since it is the one that connects com.github.atais:test_2.11:0.0.3 to the unwanted org.slf4j:slf4j-log4j12:1.7.10

    And modify it:

    libraryDependencies += "org.apache.hadoop" % "hadoop-common" % "2.8.1" exclude("org.slf4j", "slf4j-log4j12")
    

    Easy way

    simply add the merging strategy flag for conflicting paths:

    assemblyMergeStrategy in assembly := {
      ...
      case PathList("org", "slf4j", xs@_*) => MergeStrategy.first
      case x => (assemblyMergeStrategy in assembly).value(x)
    }
    

提交回复
热议问题