2

enter code hereIs there a way to turn off reduplication in SBT's assembly plugin?

I've been cleaning out an sbt assembly build the old fashioned way, using sbt dependency-graph to remove jar files which have differing versions of the same file.

  • if I simply use last for the strategy, the resulting jar file failst with a duplicate entry when running makeJar.
  • if I use discard for the strategy, the resulting jar file is trivial, with nothing in it.

However, in my case, this isn't a huge problem : I'd like to simply avoid doing reduplication entirely, and later at run time if I have issues, clean up dependency conflicts. This is normally how tools like maven seem to work, and I'd like to use SBT to build jars which are similar to the fat jars which are built by those tools.

jayunit100
  • 17,388
  • 22
  • 92
  • 167
  • Note : I've successfully found a way to solve this by using ```mergeStrategy in assembly := {MergeStrategy.discard... ``` in by build.sbt file. not sure if that is a good solution or not though. – jayunit100 Jan 25 '15 at 17:26

1 Answers1

0

I was able to come up with a reasonable merge strategy, it looks like this, taken from https://github.com/moser/foxtrot_mike_client/blob/master/build.sbt.

mergeStrategy in assembly := { 
  case n if n.startsWith("META-INF/eclipse.inf") => MergeStrategy.discard
  case n if n.startsWith("META-INF/ECLIPSEF.RSA") => MergeStrategy.discard
  case n if n.startsWith("META-INF/ECLIPSE_.RSA") => MergeStrategy.discard
  case n if n.startsWith("META-INF/ECLIPSEF.SF") => MergeStrategy.discard
  case n if n.startsWith("META-INF/ECLIPSE_.SF") => MergeStrategy.discard
  case n if n.startsWith("META-INF/MANIFEST.MF") => MergeStrategy.discard
  case n if n.startsWith("META-INF/NOTICE.txt") => MergeStrategy.discard
      case n if n.startsWith("META-INF/NOTICE") => MergeStrategy.discard
      case n if n.startsWith("META-INF/LICENSE.txt") =>     
 MergeStrategy.discard
      case n if n.startsWith("META-INF/LICENSE") => MergeStrategy.discard
      case n if n.startsWith("rootdoc.txt") => MergeStrategy.discard
      case n if n.startsWith("readme.html") => MergeStrategy.discard
      case n if n.startsWith("readme.txt") => MergeStrategy.discard
      case n if n.startsWith("library.properties") => MergeStrategy.discard
      case n if n.startsWith("license.html") => MergeStrategy.discard
      case n if n.startsWith("about.html") => MergeStrategy.discard
      case _ => MergeStrategy.deduplicate
    }

The answer to the original question, is simply, that you have to define a MergeStrategy when using sbt assembly, and there are plenty of templates (like this one) which you can borrow and paste into your build.sbt file.

jayunit100
  • 17,388
  • 22
  • 92
  • 167