播放JSON库和sbt程序集合并错误

Play JSON library and sbt assembly merge error

即使是一个简单的 Hello 程序,如果我将 play-json 作为库依赖项添加到 build.sbt 文件中,我在执行 [=26] 时总是会出现合并错误=] sbt 中的命令(sbt-assembly 插件)。

[error] stack trace is suppressed; run last assembly for the full output
[error] (assembly) deduplicate: different file contents found in the following:
[error] /home/heitor/.cache/coursier/v1/https/repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-annotations/2.10.1/jackson-annotations-2.10.1.jar:module-info.class
[error] /home/heitor/.cache/coursier/v1/https/repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-core/2.10.1/jackson-core-2.10.1.jar:module-info.class
[error] /home/heitor/.cache/coursier/v1/https/repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-databind/2.10.1/jackson-databind-2.10.1.jar:module-info.class
[error] /home/heitor/.cache/coursier/v1/https/repo1.maven.org/maven2/com/fasterxml/jackson/datatype/jackson-datatype-jdk8/2.10.1/jackson-datatype-jdk8-2.10.1.jar:module-info.class
[error] /home/heitor/.cache/coursier/v1/https/repo1.maven.org/maven2/com/fasterxml/jackson/datatype/jackson-datatype-jsr310/2.10.1/jackson-datatype-jsr310-2.10.1.jar:module-info.class

MergeApp.scala

object MergeApp extends App {
  println("Hello")
}

build.sbt

name := "MergeBug"

version := "0.1"

scalaVersion := "2.13.1"

val playJsonVersion = "2.8.1"

libraryDependencies ++= Seq("com.typesafe.play" %% "play-json" % playJsonVersion)

project/build.属性

sbt.version = 1.3.8

project/plugins.sbt

addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.10")

您需要定义自定义合并策略。参见 https://github.com/sbt/sbt-assembly#merge-strategy

由于 module-info.class 文件仅对 Java 9+ 模块有用,您可以安全地丢弃它们:

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