How is the shadow before compiling with SBT?

Our project consists mainly of two parts

  • Build.scala where the root project is located
  • BuildShaded.scala , where some external dependencies are obscured by sbt-assembly . Shaded banks will depend on subprojects in the root project with unmanagedJars set up.

The question is how to build a shaded project before compiling the root project. Otherwise, the root project cannot be compiled, since these classes are not available in shaded banks.

+7
scala sbt sbt-assembly
source share
1 answer

As I said in the comments, I would go the other way. If you use dependencies as managed dependencies, you can obscure them both in the library itself and inside your project.

Let's look at an example:

Suppose I have a project that takes a dependency on com.typesafe.config . I can shade it inside my own library, i.e. inside the com.typesafe.config code, as well as in the consumption library.

You define it as follows:

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

Which basically means "take something that creatures using com.typesafe.config , and drop it before my_conf ."

Please note that we use both inLibrary and inProject . The first means "change package names inside com.typesafe.config " and inProject means "change all links to com.typesafe.config inside my code."

Now the result is as follows:

Here's what the package looks like internally ( my_conf was originally com.typesafe.config before shading):

Configafe Config code

And this is the package your code refers to:

Your code

+4
source share

All Articles