Uploaded image for project: 'Maven Shade Plugin'
  1. Maven Shade Plugin
  2. MSHADE-302

maven-shade-plugin fails to minimize JAR with Java 11

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 3.2.1
    • Labels:
      None
    • Environment:
      maven-shade-plugin 3.2.1-SNAPSHOT or master branch.

      openjdk version "11" 2018-09-25
      OpenJDK Runtime Environment 18.9 (build 11+28)
      OpenJDK 64-Bit Server VM 18.9 (build 11+28, mixed mode)
    • Flags:
      Patch

      Description

      While checking whether maven-shade-plugin is Java 11 compatible or not, I noticed that it fails when minimizeJar is set to true and a class contains a nested static class.

      I was able to reproduce the issue by patching the shading-with-java-11-sources integration test:

      diff --git a/src/it/shading-with-java-11-sources/pom.xml b/src/it/shading-with-java-11-sources/pom.xml
      index 0ea23fe..34898b7 100644
      --- a/src/it/shading-with-java-11-sources/pom.xml
      +++ b/src/it/shading-with-java-11-sources/pom.xml
      @@ -76,2 +76,3 @@ under the License.
                   <configuration>
      +              <minimizeJar>true</minimizeJar>
                     <shadedArtifactAttached>true</shadedArtifactAttached>
      diff --git a/src/it/shading-with-java-11-sources/src/main/java/org/apache/maven/plugins/shade/its/App.java b/src/it/shading-with-java-11-sources/src/main/java/org/apache/maven/plugins/shade/its/App.java
      index a92156e..c9fc298 100644
      --- a/src/it/shading-with-java-11-sources/src/main/java/org/apache/maven/plugins/shade/its/App.java
      +++ b/src/it/shading-with-java-11-sources/src/main/java/org/apache/maven/plugins/shade/its/App.java
      @@ -49,2 +49,5 @@ public class App
           }
      +
      +    static class Foo {
      +    }
       }
      

      Running mvn -Prun-its -Dinvoker.test="java-11" verify leads to the following exception

      Caused by: java.lang.UnsupportedOperationException: This feature requires ASM7
          at org.objectweb.asm.ClassVisitor.visitNestMember (ClassVisitor.java:236)
          at org.objectweb.asm.ClassVisitor.visitNestMember (ClassVisitor.java:239)
          at org.objectweb.asm.commons.ClassRemapper.visitNestMember (ClassRemapper.java:190)
          at org.objectweb.asm.ClassReader.accept (ClassReader.java:651)
          at org.objectweb.asm.ClassReader.accept (ClassReader.java:391)
          at org.vafer.jdependency.Clazzpath.addClazzpathUnit (Clazzpath.java:179)
          at org.vafer.jdependency.Clazzpath.addClazzpathUnit (Clazzpath.java:140)
          at org.apache.maven.plugins.shade.filter.MinijarFilter.<init> (MinijarFilter.java:97)
          at org.apache.maven.plugins.shade.mojo.ShadeMojo.getFilters (ShadeMojo.java:834)
          at org.apache.maven.plugins.shade.mojo.ShadeMojo.execute (ShadeMojo.java:434)
          at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
          at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:208)
          at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:154)
          at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:146)
          at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
          at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
          at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
          at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
          at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
          at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
          at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
          at org.apache.maven.cli.MavenCli.execute (MavenCli.java:954)
          at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:288)
          at org.apache.maven.cli.MavenCli.main (MavenCli.java:192)
          at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
          at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
          at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
          at java.lang.reflect.Method.invoke (Method.java:566)
          at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289)
          at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229)
          at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415)
          at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356)
      

      I have not yet troubleshooted the issue. Other jdendency users seems to be facing a similar issue, see https://github.com/tcurdt/jdependency/issues/21. I have also seen a similar stack trace in Spring SPR-17371.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                olamy Olivier Lamy (*$^¨%`£)
                Reporter:
                clement@unportant.info Clément MATHIEU
              • Votes:
                1 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: