apache / apache/maven-shade-plugin
[MSHADE-406] relocated multi-release classes aren't moved to a new directory
- Dominant language
- Java
- Stars
- 188
- Forks
- 103
- Avg merge
- 16h 39m
- Merged PRs (30d)
- 4
Description
**[Brian Gruber](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=bgruber-datadog)** opened **[MSHADE-406](https://issues.apache.org/jira/browse/MSHADE-406?redirect=false)** and commented
In a project in which a dependency has a multi-release jar, classes that match a relocation pattern and are in the `META-INF/versions` directories are not moved to the new directory structure. They are, however, rewritten so that the class file itself specifies the new package name.
Sample project: https://gist.github.com/bgruber/5fb045759505da5150d3e93ec5c6010e
The generated jar file still contains classes like this:
```java
$ jar tf target/relocation-test-SNAPSHOT-1.0.jar | grep versions | head
META-INF/versions/
META-INF/versions/9/
META-INF/versions/9/org/
META-INF/versions/9/org/bouncycastle/
META-INF/versions/9/org/bouncycastle/crypto/
META-INF/versions/9/org/bouncycastle/crypto/AsymmetricCipherKeyPair.class
META-INF/versions/9/org/bouncycastle/crypto/Digest.class
META-INF/versions/9/org/bouncycastle/crypto/CryptoServicesRegistrar$Property.class
META-INF/versions/9/org/bouncycastle/crypto/CryptoServicesRegistrar.class
META-INF/versions/9/org/bouncycastle/crypto/KeyGenerationParameters.class
```
I expect these class files to be under `META-INF/versions/9/com/dd/org/bouncycastle`. Extracting one of them from the jar and examining it, the class file does appear to have been modified to have the new package name:
```java
$ jar xf target/relocation-test-SNAPSHOT-1.0.jar META-INF/versions/9/org/bouncycastle/crypto/Digest.class
$ javap META-INF/versions/9/org/bouncycastle/crypto/Digest.class
Compiled from "Digest.java"
public interface com.dd.org.bouncycastle.crypto.Digest {
public abstract java.lang.String getAlgorithmName();
public abstract int getDigestSize();
public abstract void update(byte);
public abstract void update(byte[], int, int);
public abstract int doFinal(byte[], int);
public abstract void reset();
}
```
---
**Issue Links:**
- [PHOENIX-7011](https://issues.apache.org/jira/browse/PHOENIX-7011) Remove relocated multi-release classes from shaded artifacts
(_**"causes"**_)
**Remote Links:**
- [GitHub Pull Request #202
](https://github.com/apache/maven-shade-plugin/pull/202)
4 votes, 5 watchers
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the linked sample project and reproduce the shaded JAR, then inspect how relocation handles classes under META-INF/versions. Compare the generated paths with the expected META-INF/versions/9/com/dd/org/bouncycastle layout and verify with javap that the relocated class names remain correct.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100