Skip to content

Commit 3b9e61e

Browse files
authored
Fix shading of modules (testcontainers#1342, testcontainers#1390)
1 parent 8a8548a commit 3b9e61e

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

build.gradle

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,34 @@ subprojects {
5656
configurations = []
5757
classifier = null
5858

59-
// Keep docker-java's package inside the final jar
60-
relocate("com.github.dockerjava", "com.github.dockerjava")
61-
}
59+
doFirst {
60+
// See https://github.com/johnrengelman/shadow/blob/5.0.0/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/tasks/ConfigureShadowRelocation.groovy
61+
Set<String> packages = []
62+
// Always read from core's configurations
63+
for (configuration in tasks.getByPath(":testcontainers:shadowJar").configurations) {
64+
for (jar in configuration.files) {
65+
def jf = new java.util.jar.JarFile(jar)
66+
for (entry in jf.entries()) {
67+
def name = entry.name
68+
if (name.endsWith(".class")) {
69+
packages.add(name.substring(0, name.lastIndexOf('/')))
70+
}
71+
}
72+
jf.close()
73+
}
74+
}
75+
for (pkg in packages) {
76+
pkg = pkg.replaceAll('/', '.')
6277

63-
task relocateShadowJar(type: com.github.jengelman.gradle.plugins.shadow.tasks.ConfigureShadowRelocation) {
64-
target = tasks.shadowJar
65-
prefix = "org.testcontainers.shaded"
66-
}
78+
if (pkg.startsWith("com.github.dockerjava.")) {
79+
// Keep docker-java's package inside the final jar
80+
continue;
81+
}
6782

68-
tasks.shadowJar.dependsOn tasks.relocateShadowJar
83+
tasks.shadowJar.relocate(pkg, "org.testcontainers.shaded.${pkg}")
84+
}
85+
}
86+
}
6987

7088
publishing {
7189
publications {

0 commit comments

Comments
 (0)