Maven shade plugin failed to execute goal?
Asked Answered
P

4

12

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?

Precipitancy answered 7/9, 2018 at 11:9 Comment(2)
Please check maven-shade-plugin version 3.1.1 instead of 3.1.0...cause there was an fix in 3.1.1 explicitly for JDK 10...(mail-archive.com/[email protected]/msg00837.html)Garrote
@Garrote I have upgraded as you suggestedPrecipitancy
B
15

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>
Biddick answered 13/9, 2018 at 2:40 Comment(1)
For me, I had to change the version to 3.2.1. Not sure why but got the same error as OP when using 3.2.0. Project is using jdk 11Setscrew
P
2

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

Precipitancy answered 9/9, 2018 at 17:8 Comment(0)
W
0

Please take a look at this tutorial from Maven: https://maven.apache.org/plugins/maven-shade-plugin/usage.html

The configuration of the plugin changed a bit over past and you don't need to specify the transformations.

An example looks like this for 3.2.1:

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>3.2.1</version>
        <configuration>
          <!-- put your configurations here -->
        </configuration>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  ...
</project>
Waist answered 10/1, 2020 at 11:17 Comment(0)
C
0

I could solve this problem by upgrading to latest plugin version

        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-shade-plugin</artifactId>
          <version>3.4.1</version>
        </plugin>
Calle answered 18/4, 2023 at 14:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.