sbt / sbt-assembly

Deploy über-JARs. Restart processes. (port of codahale/assembly-sbt)
MIT License
1.95k stars 224 forks source link

Shading with inLibrary doesn't work #405

Open antonipp opened 4 years ago

antonipp commented 4 years ago

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!

ericxsun commented 3 years ago

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

Vishvin95 commented 3 years ago

Same with sbt 1.4.3 and assembly-0.14.10.

sriggin commented 3 years ago

Same with sbt 1.4.8 and sbt-assembly 1.0.0

peter-salt commented 1 year ago

Hi

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

avgolubev commented 1 year ago

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
    )
MasseGuillaume commented 10 months ago

@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 commented 10 months ago

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 commented 10 months ago

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