微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

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

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

解决方法

我不熟悉 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 罐。

使用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

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

在这种情况下,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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。