Migrate maven-shade-plugin to use gradle shadow plugin

plugins

(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:

<plugin>
        <artifactId>maven-shade-plugin</artifactId>
        <version>3.0.0</version>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
            <configuration>
              <relocations>
                <relocation>
                  <pattern>org.objectweb</pattern>
                  <shadedPattern>blablabla.org.objectweb</shadedPattern>
                </relocation>
              </relocations>
            </configuration>
          </execution>
        </executions>
      </plugin>

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

apply plugin: 'com.github.johnrengelman.plugin-shadow'
buildscript {
  repositories {
    jcenter()
  }
  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.