Why Maven assembly works when SBT assembly find conflicts

后端 未结 3 745
日久生厌
日久生厌 2021-02-08 11:54

The title could also be:
What are the differences between Maven and SBT assembly plugins.

I have found this to be an issue, while migrating a proje

3条回答
  •  温柔的废话
    2021-02-08 12:25

    From the build.sbt I can see that their is no Merge-Strategy in you build. Plus there is a Rogue "," in your libraryDependencies Key placed after the dependency of "org.apache.cassandra" % "cassandra-all" % "3.4" in your build.sbt in the project to which the link you have shared above.

    A merge strategy is required to handle all the duplicate files and in the jar as well as versions. The following one is an example of how to get one in place in your build.

    assemblyMergeStrategy in assembly := {
      case m if m.toLowerCase.endsWith("manifest.mf")       => MergeStrategy.discard
      case m if m.toLowerCase.matches("meta-inf.*\\.sf$")   => MergeStrategy.discard
      case "reference.conf"                                 => MergeStrategy.concat
      case x: String if x.contains("UnusedStubClass.class") => MergeStrategy.first
      case _                                                => MergeStrategy.first
    }
    

    You could try writing a simple build file if you do not have sub-projects in your project. You can try the following build.sbt.

    name := "assembly-test",
    
    version := "0.1",
    
    scalaVersion := "2.12.4",
    
    libraryDependencies ++= Seq(
          "com.netflix.astyanax" % "astyanax-cassandra" % "3.9.0",
          "org.apache.cassandra" % "cassandra-all" % "3.4"
    )
    
    mainClass in assembly := Some("com.atais.cassandra.MainClass")
    
    assemblyMergeStrategy in assembly := {
          case m if m.toLowerCase.endsWith("manifest.mf")       => MergeStrategy.discard
          case m if m.toLowerCase.matches("meta-inf.*\\.sf$")   => MergeStrategy.discard
          case "reference.conf"                                 => MergeStrategy.concat
          case x: String if x.contains("UnusedStubClass.class") => MergeStrategy.first
          case _                                                => MergeStrategy.first
        }
    

提交回复
热议问题