Search code examples
scalamergesbt-assemblyplay-json

Play JSON library and sbt assembly merge error


Even with a simple Hello program, if I add the play-json as a library dependency in the build.sbt file, I always get the an merge error when I execute the 'assembly' command in sbt (sbt-assembly plugin).

[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.properties

sbt.version = 1.3.8

project/plugins.sbt

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

Solution

  • You need to define a custom merge strategy. See https://github.com/sbt/sbt-assembly#merge-strategy

    Since module-info.class files are only useful for Java 9+ modules, you can safely discard them:

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