Migrate maven-shade-plugin to use gradle shadow plugin


(Jiaqi Guan) #1

I’m currently migrating my project from Maven to Gradle. And one of my maven pom.xml has a plugins like follows:


And in my build.gradle, I wrote something like follows.

apply plugin: 'com.github.johnrengelman.plugin-shadow'
buildscript {
  repositories {
  dependencies {
    classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.4'

shadowJar {
  baseName = 'original-' + project.name
  classifier = null
  relocate 'org.objectweb', 'blablabla.org.objectweb'

The result is that it do generate a shadow .jar file. But after I compare this jar file with the one from Maven. I unjar them. They have different directory structure and several .class files are in different folders.
I’m not sure I did it correctly. Based on my understanding, I think they should generate the exactly some .jar. Could someone help me if I did something wrong here? Thank you.

(James Justinic) #2

Shade and Shadow are designed for similar purposes, but they are different implementations. There isn’t a guarantee that they should produce exactly the same JAR. That may or may not really be an issue depending on what you’re relying on.

Your only explicit requirement seems to be that org.objectweb is relocated to blablabla.org.objectweb, which is conveyed in both configurations. It would be helpful if you could provide concrete examples of source files that end up in different locations to determine what implementation differences are responsible and how to configure Shadow if these really are critical.