如何在使用 SBT 编译之前进行遮蔽? [英] how to shade before compile with SBT?

查看:18
本文介绍了如何在使用 SBT 编译之前进行遮蔽?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是您的代码将引用的包:

Our project mainly consists of two parts

  • Build.scala where the root project lies
  • BuildShaded.scala where some external dependencies are shaded with sbt-assembly. The shaded jars will be depended upon by sub projects under the root project through unmanagedJars setting.

The question is how to assembly the shaded project before compiling the root project. Otherwise, the root project will fail to compile since those classes in the shaded jars are not available.

解决方案

As I said in the comments, I would take a different route. If you take on the dependencies as managed dependencies, you can shade them both in the library itself and inside your project.

Let's see an example:

Assume that I have a project which takes dependency on com.typesafe.config. I can shade it inside it's own library, meaning inside the code of com.typesafe.config, and also in the consuming library.

You define it like this:

assemblyShadeRules in assembly ++= Seq(
  ShadeRule.rename("com.typesafe.config.**" -> "my_conf.@1")
    .inLibrary("com.typesafe" % "config" % "1.3.0")
    .inProject
)

Which basically means "take any package that beings with com.typesafe.config and shade it to my_conf."

Note that we're using both inLibrary and inProject. The former means "change the package names and references to them inside com.typesafe.config" and inProject means "change all references to com.typesafe.config inside my code".

Now, the output of that looks like this:

This is how the package internally looks now (my_conf was originally com.typesafe.config before shading):

And this is the package your code will reference:

这篇关于如何在使用 SBT 编译之前进行遮蔽?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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