sbt-assembly 是否应该执行类似“maven-shade-plugin"的类重定位? [英] Should sbt-assembly perform a "maven-shade-plugin"-like relocation of classes?

查看:31
本文介绍了sbt-assembly 是否应该执行类似“maven-shade-plugin"的类重定位?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

sbt-assembly 合并策略的描述称为rename 听起来像它可能允许类似于 maven-shade-plugin 它将重新定位类及其引用以允许管理不兼容版本的库.

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.

sbt-assembly 是否适合执行该功能?

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

推荐答案

2015 年 9 月更新:

sbt-assembly 0.14.0 添加了阴影支持.

sbt-assembly 0.14.0 adds shading support.

sbt-assembly 可以从您的项目或库依赖项中屏蔽类.在 Jar Jar Links 的支持下,字节码转换(通过 ASM)用于更改对重命名类的引用.

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
)

这篇关于sbt-assembly 是否应该执行类似“maven-shade-plugin"的类重定位?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆