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?

2
  • 3
    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) Commented Sep 7, 2018 at 11:25
  • @khmarbaise I have upgraded as you suggested Commented Sep 7, 2018 at 11:33

4 Answers 4

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> 
Sign up to request clarification or add additional context in comments.

1 Comment

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 11
2

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

Comments

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> 

Comments

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> 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.