Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven shade plugin failed to execute goal?

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?

like image 627
jMan Avatar asked Sep 07 '18 11:09

jMan


People also ask

What maven shade plugin is for?

This plugin provides the capability to package the artifact in an uber-jar, including its dependencies and to shade - i.e. rename - the packages of some of the dependencies.


2 Answers

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>
like image 146
Naman Avatar answered Oct 11 '22 18:10

Naman


As said in the edit, setting minimizeJar to false solves my problem.

like image 22
jMan Avatar answered Oct 11 '22 20:10

jMan