Skip to content

Commit de256ad

Browse files
committed
Added workaround to move multi-release classes when shading BouncyCastle
1 parent 670c5fa commit de256ad

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

sdk/keyvault/azure-security-keyvault-jca/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
### Bugs Fixed
1010
- Fixed the NPE where the token object was not returned when the credential information was incorrect.
11+
- Fixed an issue where release-specific classes from BouncyCastle were not properly shaded for Java 9 and above, leading to potential class loading issues in multi-release JARs. ([#47127](https://github.com/Azure/azure-sdk-for-java/pull/47127))
1112

1213
### Other Changes
1314
- Included the `org.brotli:dec` library in the list of shaded dependencies to avoid issues when generating and publishing docs to MSLearn.

sdk/keyvault/azure-security-keyvault-jca/pom.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,11 @@
162162
<exclude>META-INF/*.DSA</exclude>
163163
<exclude>META-INF/*.RSA</exclude>
164164
<exclude>META-INF/services/java.security.Provider</exclude>
165+
<!-- Exclude OSGI metadata since it references original (unshaded) package names
166+
and is not applicable after relocation -->
167+
<exclude>**/OSGI-INF/**</exclude>
168+
<!-- Exclude Bouncy Castle's module-info since it references unshaded packages. -->
169+
<exclude>**/module-info.class</exclude>
165170
</excludes>
166171
</filter>
167172
</filters>
@@ -170,6 +175,21 @@
170175
<pattern>org.bouncycastle</pattern>
171176
<shadedPattern>com.azure.security.keyvault.jca.implementation.shaded.org.bouncycastle</shadedPattern>
172177
</relocation>
178+
<!-- Manually relocate Bouncy Castle multi-release classes to the correct shaded package.
179+
This workaround is needed because the maven-shade-plugin (as of 3.6.1) relocates the
180+
bytecode but does not move the class files to the shaded directory structure (MSHADE-406).
181+
This additional relocation rule matches the file path pattern and moves multi-release
182+
classes to preserve Java 9+ optimizations while preventing package leakage.
183+
Based on: https://github.com/datafaker-net/datafaker/pull/1008
184+
See:
185+
- https://github.com/apache/maven-shade-plugin/pull/202
186+
- https://issues.apache.org/jira/browse/MSHADE-406
187+
- https://github.com/Azure/azure-sdk-for-java/issues/45277 -->
188+
<relocation>
189+
<pattern>META-INF/versions/(\d+)/org/bouncycastle</pattern>
190+
<shadedPattern>META-INF/versions/$1/com/azure/security/keyvault/jca/implementation/shaded/org/bouncycastle</shadedPattern>
191+
<rawString>true</rawString>
192+
</relocation>
173193
</relocations>
174194
<transformers>
175195
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>

0 commit comments

Comments
 (0)