GradleUp / shadow

Gradle plugin to create fat/uber JARs, apply file transforms, and relocate packages for applications and libraries. Gradle version of Maven's Shade plugin.
https://www.gradleup.com/shadow/
Apache License 2.0
3.69k stars 389 forks source link

Relocate Exclude doesn't exclude all relocates #305

Open furrowb opened 7 years ago

furrowb commented 7 years ago

I was creating a Gradle plugin to help standardize some of our build processes and when we started using exclude for relocates, we noticed some issues. By default, we are relocating com and org based projects but needed some exclusions.

When specifying excludes for relocates using org.apache.cxf*/**, this excluded the jar with the related class files in question from being relocated. However, it does NOT exclude relocating references in other jars.

The library this affected was compile (group: 'io.cloudsoft.windows', name: 'winrm4j', version: '0.5.0' ), which was also being excluded. I had the jar instead of the maven dependency of org.apache.cxf but it was version 3.1.10. Decompiling the jar showed that the jar had its references to org.apache.cnf relocated to our given relocation path, com/new/path/org.apache.cnf.ClassFile (note the slashes).

Shadow Version

2.0.0

Gradle Version

3.5

Expected Behavior

Excluding org.apache.cxf*/** from a relocate excludes any relocation from happening for this classpath.

Actual Behavior

Excluding org.apache.cxf*/** from a relocate excludes the classes from being relocated but still relocates string references.

Gradle Build Script(s)

No script since this is was a Gradle plugin, written in a Groovy project.

Content of Shadow JAR (jar tf <jar file> - post link to GIST if too long)

https://gist.github.com/furrowb/923f30596eb0c4f563a6f750e5bb2cdc

furrowb commented 7 years ago
image

Here's an example screenshot of it relocating the string being referenced in a class, even though the classes themselves have been excluded.

cholve commented 6 years ago

@furrowb I also had this problem, but was able to get it working by specifying the package using slashes instead of periods.

    relocate ("org.apache", "shaded.org.apache") {
      exclude "org/apache/logging/**"
    }
guillermo-varela commented 3 years ago

@furrowb I also had this problem, but was able to get it working by specifying the package using slashes instead of periods.

    relocate ("org.apache", "shaded.org.apache") {
      exclude "org/apache/logging/**"
    }

That solution doesn't seem to work anymore. I'm excluding a package from relocation and a class inside the excluded package which has a string value referencing a resource inside the excluded package ends up with the string "relocated".

jeff303 commented 7 months ago

@furrowb I also had this problem, but was able to get it working by specifying the package using slashes instead of periods.

    relocate ("org.apache", "shaded.org.apache") {
      exclude "org/apache/logging/**"
    }

Thanks, this finally worked for me.

Not working:

<relocation>
    <pattern>io.grpc</pattern>
    <shadedPattern>my.prefix.io.grpc</shadedPattern>
    <excludes>
        <exclude>io.grpc.netty.*</exclude>
    </excludes>
</relocation>

Working:

<relocation>
    <pattern>io.grpc</pattern>
    <shadedPattern>my.prefix.io.grpc</shadedPattern>
    <excludes>
        <exclude>io/grpc/netty/**</exclude>
    </excludes>
</relocation>

This is on maven-shade-plugin:3.5.1. They really need to update their docs.