【问题标题】:How to fix the dependency graph to resolve deduplicate errors?如何修复依赖图以解决重复数据删除错误?
【发布时间】:2021-09-07 02:59:53
【问题描述】:

我遇到了一些像下面这样的重复数据删除错误,这表明我的一些依赖项导入了其他包含具有相同路径名的文件的依赖项。由于它们具有相同的路径,因此它们不能一起包含在我尝试使用 sbt-assembly 创建的 jar 文件中。

我知道修复它的干净方法是修复我的依赖项。下面示例中相互冲突的依赖项似乎是reactive-streamsreactive-streams-flow-adapters,但我不确定它们是什么以及它们来自哪里。如何找到我的哪些依赖项正在导入它们?

如果我能解决这个问题,我该如何解决?除了删除其中一个之外,还有其他方法吗?

重复数据删除错误示例:

[error] (assembly) deduplicate: different file contents found in the following:
[error] /home/guillaume/.cache/coursier/v1/https/repo1.maven.org/maven2/org/reactivestreams/reactive-streams-flow-adapters/1.0.2/reactive-streams-flow-adapters-1.0.2.jar:org/reactivestreams/FlowAdapters$FlowPublisherFromReactive.class
[error] /home/guillaume/.cache/coursier/v1/https/repo1.maven.org/maven2/org/reactivestreams/reactive-streams/1.0.3/reactive-streams-1.0.3.jar:org/reactivestreams/FlowAdapters$FlowPublisherFromReactive.class

这是我的依赖项列表,如果有帮助的话:

libraryDependencies += "com.fasterxml.jackson.core" % "jackson-databind" % "2.12.2",
libraryDependencies += "com.novocode" % "junit-interface" % "0.11" % "test",
libraryDependencies += "com.softwaremill.sttp.client3" %% "core" % "3.3.6",
libraryDependencies += "com.softwaremill.sttp.client3" %% "httpclient-backend-zio" % "3.3.6",
libraryDependencies += "dev.zio" %% "zio" % "1.0.9",
// libraryDependencies += "dev.zio" %% "zio-streams" % "1.0.9",
libraryDependencies += "org.apache.commons" % "commons-compress" % "1.20",
libraryDependencies += "org.scalactic" %% "scalactic" % "3.2.9",
libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.9" % "test",
libraryDependencies += ("tech.sparse" %%  "toml-scala" % "0.2.2").cross(CrossVersion.for3Use2_13),

【问题讨论】:

    标签: sbt sbt-assembly


    【解决方案1】:

    我不熟悉 Reactive Streams,但看起来他们在补丁版本期间进行了一些更改,并在 1.0.3 中移动了类。见Reactive Streams 1.0.3 is here!

    当我们发布 1.0.2 时,我们发布了一个兼容性/转换库,可以在 java.util.concurrent.Floworg.reactivestreams 命名空间之间进行无缝转换——在 1.0.3 中,这些适配器被包含在主 1.0.3 jar 中。

    使用dependencyTree调查传递依赖

    如何找到我的哪些依赖项正在导入它们?

    如果你使用的是最新的 sbt 1.5.4,它默认内置了 Johannes 的依赖图插件,所以你可以从 sbt shell 运行dependencyTree

    sbt:root> dependencyTree
    [info] root:root_2.13:0.1.0-SNAPSHOT [S]
    ....
    [info]   +-com.softwaremill.sttp.client3:httpclient-backend-zio_2.13:3.3.6 [S]
    [info]   | +-com.softwaremill.sttp.client3:httpclient-backend_2.13:3.3.6 [S]
    [info]   | | +-com.softwaremill.sttp.client3:core_2.13:3.3.6 [S]
    [info]   | | | +-com.softwaremill.sttp.model:core_2.13:1.4.7 [S]
    [info]   | | | +-com.softwaremill.sttp.shared:core_2.13:1.2.5 [S]
    [info]   | | | +-com.softwaremill.sttp.shared:ws_2.13:1.2.5 [S]
    [info]   | | |   +-com.softwaremill.sttp.model:core_2.13:1.4.7 [S]
    [info]   | | |   +-com.softwaremill.sttp.shared:core_2.13:1.2.5 [S]
    [info]   | | |
    [info]   | | +-org.reactivestreams:reactive-streams-flow-adapters:1.0.2
    [info]   | |   +-org.reactivestreams:reactive-streams:1.0.2 (evicted by: 1.0.3)
    [info]   | |   +-org.reactivestreams:reactive-streams:1.0.3
    ....
    

    这告诉我们org.reactivestreams:reactive-streams-flow-adapters:1.0.2 是从com.softwaremill.sttp.client3:httpclient-backend_2.13:3.3.6 拉进来的。

    不包括反应流-流适配器

    如果我能解决这个问题,我该如何解决?除了删除其中一个之外,还有其他方法吗?

    在这种情况下,reactive-streams-flow-adapters 在 1.0.3 之后被 reactive-streams 包含,所以我认为我们可以将其从依赖项中排除如下:

        libraryDependencies += ("com.softwaremill.sttp.client3" %% "httpclient-backend-zio" % "3.3.6")
          .exclude("org.reactivestreams", "reactive-streams-flow-adapters"),
    

    忽略 module-info.class

    要忽略module-info.class,我们可以将其添加到build.sbt

    ThisBuild / assemblyMergeStrategy := {
      case "module-info.class" => MergeStrategy.discard
      case x =>
        val oldStrategy = (ThisBuild / assemblyMergeStrategy).value
        oldStrategy(x)
    }
    

    结果

    sbt:root> assembly
    [info] Strategy 'discard' was applied to 10 files (Run the task at debug level to see details)
    [success] Total time: 3 s, completed Jun 26, 2021 6:02:04 PM
    

    【讨论】:

      猜你喜欢
      • 2021-10-16
      • 2020-11-29
      • 2022-01-21
      • 1970-01-01
      • 1970-01-01
      • 2014-11-12
      • 2018-04-07
      • 2023-03-16
      • 2021-08-22
      相关资源
      最近更新 更多