Should sbt-assembly perform a “maven-shade-plugin”-like relocation of classes?

谁说胖子不能爱 提交于 2019-12-22 06:45:11

问题


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)
    }
  }
}

回答1:


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
)


来源:https://stackoverflow.com/questions/28846389/should-sbt-assembly-perform-a-maven-shade-plugin-like-relocation-of-classes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!