Skip to content

Commit

Permalink
Fix shading of modules (#1342, #1390)
Browse files Browse the repository at this point in the history
  • Loading branch information
bsideup committed Apr 11, 2019
1 parent 8a8548a commit 3b9e61e
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions build.gradle
Expand Up @@ -56,16 +56,34 @@ subprojects {
configurations = []
classifier = null

// Keep docker-java's package inside the final jar
relocate("com.github.dockerjava", "com.github.dockerjava")
}
doFirst {
// See https://github.com/johnrengelman/shadow/blob/5.0.0/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/tasks/ConfigureShadowRelocation.groovy
Set<String> packages = []
// Always read from core's configurations
for (configuration in tasks.getByPath(":testcontainers:shadowJar").configurations) {
for (jar in configuration.files) {
def jf = new java.util.jar.JarFile(jar)
for (entry in jf.entries()) {
def name = entry.name
if (name.endsWith(".class")) {
packages.add(name.substring(0, name.lastIndexOf('/')))
}
}
jf.close()
}
}
for (pkg in packages) {
pkg = pkg.replaceAll('/', '.')

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

tasks.shadowJar.dependsOn tasks.relocateShadowJar
tasks.shadowJar.relocate(pkg, "org.testcontainers.shaded.${pkg}")
}
}
}

publishing {
publications {
Expand Down

0 comments on commit 3b9e61e

Please sign in to comment.