5

The description of sbt-assembly merge strategy called rename sounded like it might permit something similar to the shading operation of the maven-shade-plugin which will relocate classes and their references to permit the management of incompatible versions of libraries.

Would it be appropriate for sbt-assembly to perform that function?

I used the following merge strategy to attempt to use rename as a relocation mechanism but while it matches all the files, it passes them straight through (which is consistent with looking at the code).

assemblyMergeStrategy in assembly := { s =>
  s match {
    case PathList("com", "clearspring", "analytics", _*) => {
      println("match_cs: " + s)
      MergeStrategy.rename
    }
    case x => {
       println("x: " + x)
       val oldStrategy = (assemblyMergeStrategy in assembly).value
       oldStrategy(x)
    }
  }
}
Traveler
  • 1,048
  • 14
  • 27
  • I see part of this is answered [here](http://stackoverflow.com/questions/24596914/sbt-assembly-rename-class-with-merge-conflicts-shade) that sbt-assembly doesn't shade. Which leaves the part "would it be appropriate" ? – Traveler Mar 04 '15 at 16:27
  • Did this ever worked?? I am in the same situation... – acidghost May 01 '15 at 13:10
  • @acidghost : No, per my link, sbt-assembly won't do that transformation. You just have to monkey around with sbt excludes and they are very dependent on the current set of dependent jars. – Traveler May 07 '15 at 22:25
  • sbt now has shade support [in sbt#master via this PR](https://github.com/sbt/sbt-assembly/pull/162) – Sean Vieira Aug 29 '15 at 03:28

1 Answers1

7

Updated in September 2015:

sbt-assembly 0.14.0 adds shading support.

sbt-assembly can shade classes from your projects or from the library dependencies. Backed by Jar Jar Links, bytecode transformation (via ASM) is used to change references to the renamed classes.

assemblyShadeRules in assembly := Seq(
  ShadeRule.rename("org.apache.commons.io.**" -> "shadeio.@1").inAll
)
Eugene Yokota
  • 94,654
  • 45
  • 215
  • 319