sbt-assembly icon indicating copy to clipboard operation
sbt-assembly copied to clipboard

Shading with inLibrary doesn't work

Open antonipp opened this issue 4 years ago • 8 comments

Hi! I am trying to use ShadeRule.rename().inLibrary() but I am unable to make it work with sbt-assembly 0.15.0 and 0.14.10. I use sbt 1.0.4 with Scala 2.11.12.

Some context: I am using the "com.azure" % "azure-storage-blob" % "12.8.0" library which depends on io.netty. My goal is to shade all io.netty references in azure-storage-blob only. I want all other libraries which depend on Netty to use the provided version.

In order to achieve this, I wanted to use inLibrary but I couldn't make it work. It either doesn't shade anything at all, or it shades all io.netty packages but doesn't update the references in azure-storage-blob classes.

The only way to make shading work seems to be inAll but this also shades io.netty in all other libraries which I do not want.

I have a sample project which reproduces the issue and I have described all of the tests I've done in the README: https://github.com/antonipp/sbt-shade-rule-test/

Any help would be really appreciated!

antonipp avatar Aug 20 '20 08:08 antonipp

met the same with sbt-1.3.10 and sbt-assembly-0.14.10

ericxsun avatar Jan 22 '21 02:01 ericxsun

Same with sbt 1.4.3 and assembly-0.14.10.

Vishvin95 avatar Mar 04 '21 07:03 Vishvin95

Same with sbt 1.4.8 and sbt-assembly 1.0.0

sriggin avatar Jun 28 '21 17:06 sriggin

Hi

Any update on this please? I am also experiencing this Scala 2.12.13 SBT assembly 1.1.1 SBT 1.9.2

peter-salt avatar Jul 18 '23 05:07 peter-salt

The same for Scala 2.12.15 SBT 1.9.2 sbt-assembly 0.15.0

Addition after tests. I've done it. It has to add .inAll or .inProject after a rule. For example,

    assembly / assemblyShadeRules := Seq(
        ShadeRule.rename("org.apache.http.**" -> "shaded.httpclient.org.apache.http.@1")
          .inLibrary("com.company.somePackage" % "my-lib-kit" % "x.x.x")
          .inAll
    )

avgolubev avatar Sep 20 '23 13:09 avgolubev

@antonipp some years later :)

So let's take a look at your dependency graph: image

project -> azure-storage-blob-> azure-storage-common-> azure-core-http-netty -> io.netty

inLibrary is a bit dumb, it does not transitively collect all the dependencies, so you need to look at your dependency graph and pick the libraries you need to shade.

For the others, if you have a Scala library, there is also this bug to take into consideration: https://github.com/sbt/sbt-assembly/issues/403

MasseGuillaume avatar Nov 18 '23 22:11 MasseGuillaume

a clarification to @avgolubev comment:

if you are using inLibrary you are being more specific on the targets you want to apply shading to. If you use .inAll it will apply the shading to all the library regardless of your inLibrary filter.

MasseGuillaume avatar Nov 18 '23 22:11 MasseGuillaume

This project will shade their transitive dependencies correctly: https://github.com/coursier/sbt-shading#sbt-shading

MasseGuillaume avatar Nov 20 '23 20:11 MasseGuillaume