使用 sbt-native-packager 构建 docker 包时重复映射

Posted

技术标签:

【中文标题】使用 sbt-native-packager 构建 docker 包时重复映射【英文标题】:Duplicate mappings when building docker package using sbt-native-packager 【发布时间】:2015-12-22 00:45:25 【问题描述】:

我正在使用 sbt-native-packager 在 Scala 中构建我们基于 Akka HTTP 的应用程序的 docker 映像。但是,最近它在运行sbt docker:publishLocal 命令时开始抛出以下错误:

  [info] Loading project definition from ~/directory/project
  [info] Set current project to fortytwo-api (in build file:~/directory/)
  SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
  SLF4J: Defaulting to no-operation (NOP) logger implementation
  SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
  [info] Wrote ~/directory/target/scala-2.11/fortytwo-api_2.11-1.0.pom
  java.lang.RuntimeException: Duplicate mappings:
    ~/directory/target/docker/stage/opt/docker/lib/org.scalaz.scalaz-core_2.11-7.1.0.jar
  from
    ~/.ivy2/maven-cache/org/scalaz/scalaz-core_2.11/7.1.0/scalaz-core_2.11-7.1.0.jar
      ~/.ivy2/cache/org.scalaz/scalaz-core_2.11/bundles/scalaz-core_2.11-7.1.0.jar
    ~/directory/target/docker/stage/opt/docker/lib/com.typesafe.config-1.2.1.jar
  from
    ~/.ivy2/maven-cache/com/typesafe/config/1.2.1/config-1.2.1.jar
      ~/.ivy2/cache/com.typesafe/config/bundles/config-1.2.1.jar
    ~/directory/target/docker/stage/opt/docker/lib/com.google.protobuf.protobuf-java-2.5.0.jar
  from
    ~/.ivy2/maven-cache/com/google/protobuf/protobuf-java/2.5.0/protobuf-java-2.5.0.jar
      ~/.ivy2/cache/com.google.protobuf/protobuf-java/bundles/protobuf-java-2.5.0.jar
    ~/directory/target/docker/stage/opt/docker/lib/org.fusesource.leveldbjni.leveldbjni-all-1.7.jar
  from
    ~/.ivy2/maven-cache/org/fusesource/leveldbjni/leveldbjni-all/1.7/leveldbjni-all-1.7.jar
      ~/.ivy2/cache/org.fusesource.leveldbjni/leveldbjni-all/bundles/leveldbjni-all-1.7.jar
    at scala.sys.package$.error(package.scala:27)
    at sbt.Sync$.noDuplicateTargets(Sync.scala:67)
    at sbt.Sync$$anonfun$apply$1.apply(Sync.scala:25)
    at sbt.Sync$$anonfun$apply$1.apply(Sync.scala:22)
    at com.typesafe.sbt.packager.Stager$.stageFiles(Stager.scala:26)
    at com.typesafe.sbt.packager.Stager$.stage(Stager.scala:40)
    at com.typesafe.sbt.packager.docker.DockerPlugin$$anonfun$projectSettings$17.apply(DockerPlugin.scala:117)
    at com.typesafe.sbt.packager.docker.DockerPlugin$$anonfun$projectSettings$17.apply(DockerPlugin.scala:117)
    at scala.Function3$$anonfun$tupled$1.apply(Function3.scala:35)
    at scala.Function3$$anonfun$tupled$1.apply(Function3.scala:34)
    at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
    at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:40)
    at sbt.std.Transform$$anon$4.work(System.scala:63)
    at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:226)
    at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:226)
    at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:17)
    at sbt.Execute.work(Execute.scala:235)
    at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:226)
    at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:226)
    at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:159)
    at sbt.CompletionService$$anon$2.call(CompletionService.scala:28)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
  [error] (docker:stage) Duplicate mappings:
  [error]   ~/directory/target/docker/stage/opt/docker/lib/org.scalaz.scalaz-core_2.11-7.1.0.jar
  [error] from
  [error]   ~/.ivy2/maven-cache/org/scalaz/scalaz-core_2.11/7.1.0/scalaz-core_2.11-7.1.0.jar
  [error]     ~/.ivy2/cache/org.scalaz/scalaz-core_2.11/bundles/scalaz-core_2.11-7.1.0.jar
  [error]   ~/directory/target/docker/stage/opt/docker/lib/com.typesafe.config-1.2.1.jar
  [error] from
  [error]   ~/.ivy2/maven-cache/com/typesafe/config/1.2.1/config-1.2.1.jar
  [error]     ~/.ivy2/cache/com.typesafe/config/bundles/config-1.2.1.jar
  [error]   ~/directory/target/docker/stage/opt/docker/lib/com.google.protobuf.protobuf-java-2.5.0.jar
  [error] from
  [error]   ~/.ivy2/maven-cache/com/google/protobuf/protobuf-java/2.5.0/protobuf-java-2.5.0.jar
  [error]     ~/.ivy2/cache/com.google.protobuf/protobuf-java/bundles/protobuf-java-2.5.0.jar
  [error]   ~/directory/target/docker/stage/opt/docker/lib/org.fusesource.leveldbjni.leveldbjni-all-1.7.jar
  [error] from
  [error]   ~/.ivy2/maven-cache/org/fusesource/leveldbjni/leveldbjni-all/1.7/leveldbjni-all-1.7.jar
  [error]     ~/.ivy2/cache/org.fusesource.leveldbjni/leveldbjni-all/bundles/leveldbjni-all-1.7.jar

【问题讨论】:

我会尝试删除 Ivy 缓存。 我们知道这个问题。不幸的是,我们不确定这是什么原因。见github.com/sbt/sbt-native-packager/issues/657 实际上,删除 Ivy 缓存似乎奏效了。谢谢,鲁斯兰! 【参考方案1】:

似乎是相对较新的 SBT 功能,this 导致了问题。

将此添加到您的构建中:

updateOptions := updateOptions.value.withCachedResolution(false)

帮我解决了。

【讨论】:

显然,他们已经将该功能作为“实验性”进行了大约 6 年。对于多模块项目来说仍然是一个问题。 github.com/sbt/sbt/issues/413

以上是关于使用 sbt-native-packager 构建 docker 包时重复映射的主要内容,如果未能解决你的问题,请参考以下文章

如何解决使用 sbt-native-packager 构建 deb 的更改日志错误?

构建 deb 包时无法使用 sbt-native-packager 打包 cron 作业

在 SBT 中为 sbt-native-packager 的 packageMappings 构建路径

如何使用 sbt-assembly 和 sbt-native-packager 构建 deb 包以包含单个程序集 jar?

在 build.sbt 中使用 Jenkins 内部版本号通过 sbt-native-packager 构建 RPM

如何在 sbt-native-packager rpm 构建中包含 libsigar?