sbt - 如何修复依赖图以解决重复数据删除错误?

标签 sbt sbt-assembly

我遇到了一些如下所示的重复数据删除错误,这表明我的某些依赖项导入了包含具有相同路径名的文件的其他依赖项。由于它们具有相同的路径,因此它们不能一起包含在我尝试使用 sbt-assemble 创建的 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),

最佳答案

我不熟悉 Reactive Streams,但看起来他们在补丁版本中做了一些更改,并在 1.0.3 中移动了类。请参阅Reactive Streams 1.0.3 is here!

When we released 1.0.2, we shipped a compatibility/conversion library to seamlessly convert between the java.util.concurrent.Flow and the org.reactivestreams namespaces—in 1.0.3 these adapters are instead included in the main 1.0.3 jar.

使用 dependencyTree 调查传递依赖项

How can I find which of my dependencies are importing them?

如果您使用的是最新的 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.

排除 react 流流适配器

If I can figure that out, how can I fix it? Is there a way other than just removing one of them?

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

    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

关于sbt - 如何修复依赖图以解决重复数据删除错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68101801/

相关文章:

sbt - 如何避免激活器在访问“播放”页面时两次执行编译任务?

java - Play Framework项目组成

SBT:稍后如何将依赖项的传递依赖项设置为 "provided"?

scala - 有没有简单的方法可以将所有jar依赖项复制到XSBT 0.11.2中的某个目录?

postgresql - 斯卡拉玩! Postgres 连接失败

scala - 使用 sbt 运行多个应用程序

scala - sbt-assemble:使用 pom.properties 消除重复错误

SBT 程序集问题 : found String required sbt. Task[String] with <<= syntax

scala - 如何使用 scalatra 通过 sbt-assembly 创建包含 webapp 资源的可执行单个 jar

scala - play 框架 - build.sbt 中的错误解析表达式