Maven shade plugin failed to execute goal?

jMan picture jMan · Sep 7, 2018 · Viewed 10.1k times · Source

There error message in question is

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-shade-plugin:3.1.0:shade (default) on project myapp-core: Error creating shaded jar: null: IllegalArgumentException -> [Help 1]

from mvn package in the myapp-core folder. mvn clean and mvn compile work fine. My project structure is

myapp/
    myapp-acceptance-tests/
    myapp-core/
        pom.xml
    pom.xml

And myapp/pom.xml is defined by

<groupId>com.myself.myapp</groupId>
<artifactId>myapp</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<modules>
    <module>myapp-core</module>
    <module>myapp-acceptance-tests</module>
</modules>

<properties>
    <maven.compiler.source>10</maven.compiler.source>
    <maven.compiler.target>10</maven.compiler.target>
</properties>

<dependencies>
    ...
</dependencies>

And myapp/myapp-core/pom.xml is defined by

<artifactId>myapp-core</artifactId>
<packaging>jar</packaging>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <mainClass>myself.myapp.Main</mainClass>
                    </manifest>
                </archive>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>10</source>
                <target>10</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.tomcat.maven</groupId>
            <artifactId>tomcat7-maven-plugin</artifactId>
            <version>2.2</version>
            <configuration>
                <server>mytomcat7</server>
                <path>/</path>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>3.1.0</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <shadedArtifactAttached>true</shadedArtifactAttached>
                        <shadedClassifierName>shaded</shadedClassifierName>
                        <minimizeJar>true</minimizeJar>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
  • It is a much later version than the upgrade the version fix found in this question
  • the plugin is in the submodule pom rather than the parent pom as is the mistake here
  • and I have tried removing <packaging>jar</packaging> to no avail.

What does maven-shade-plugin need to successfully create the shaded jar?

EDIT: setting minimizeJar to false solves my problem, but why? Is there a better way, or a way to get the benefits of a minimised jar?

Answer

Naman picture Naman · Sep 13, 2018

You can now use the latest release maven-shade-plugin:3.2.0 as of 13.09.2018 which shall solve the error while using minimizeJar (with JDK8+) :

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-shade-plugin</artifactId>
  <version>3.2.0</version>
</plugin>