You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by "Désilets, Alain" <Al...@nrc-cnrc.gc.ca> on 2022/06/24 18:19:05 UTC
maven-shade-plugin not including dependencies
I am trying to use maven-shade-plugin for the first time to create an uber-jar and I can’t even get the simplest example to work.
For example, I created a simple pom based on the example at the top of this page:
https://maven.apache.org/plugins/maven-shade-plugin/examples/includes-excludes.html
The main difference with my pom is that I added a dependency to junit to test whether the shade plugin would include its classes in the jar. But when I run this command:
mvn clean install -X
I get a build success, but when I inspect the generated jar, I don’t see the junit classes:
$ jar -tf spike-uber-jar-0.1.0.jar
META-INF/
META-INF/MANIFEST.MF
META-INF/maven/
META-INF/maven/org.example/
META-INF/maven/org.example/spike-uber-jar/
META-INF/maven/org.example/spike-uber-jar/pom.xml
META-INF/maven/org.example/spike-uber-jar/pom.properties
Not sure what I am doing wrong. Below is the pom file:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>spike-uber-jar</artifactId>
<packaging>jar</packaging>
<version>0.1.0</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<excludes>
<exclude>classworlds:classworlds</exclude>
<exclude>junit:junit</exclude>
<exclude>jmock:*</exclude>
<exclude>*:xml-apis</exclude>
<exclude>org.apache.maven:lib:tests</exclude>
<exclude>log4j:log4j:jar:</exclude>
</excludes>
</artifactSet>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
--
Alain Désilets
alain.desilets@nrc-cnrc.gc.ca<ma...@nrc-cnrc.gc.ca>
Research Officer Agent de recherche
National Research Council Conseil national de recherches du Canada
Digital Technologies Research Centre de recherche en technologies
Center digitales
Bldg M50 Édifice M50
1200 Montreal Road, Ottawa 1200 Chemin Montréal, Ottawa
K1A 0R6 K1A 0R6
Re: maven-shade-plugin not including dependencies
Posted by Alain Désilets <al...@gmail.com>.
On Sun, Jun 26, 2022 at 9:49 AM Alexander Kriegisch <
alexander@kriegisch.name> wrote:
>
> Firstly, you are not crerating a test JAR but a regular JAR with
> application classes, so of course test-scoped dependencies like JUnit
> are not going to be contained in the uber JAR.
>
Oh, right.
Secondly, you are even explicitly excluding JUnit, so how could you
> expect it to be included, even if it was not test-scoped?
>
Boy am I red in the face right now! I had copied that example from the web
and hadn't noticed the exclusion statement. Thx for pointing out the
obvious. All works now.
Alain
>
> > <exclude>junit:junit</exclude>
>
> --
> Alexander Kriegisch
> https://scrum-master.de
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>
Re: maven-shade-plugin not including dependencies
Posted by Alexander Kriegisch <al...@kriegisch.name>.
> I get a build success, but when I inspect the generated jar, I don’t
> see the junit classes
Firstly, you are not crerating a test JAR but a regular JAR with
application classes, so of course test-scoped dependencies like JUnit
are not going to be contained in the uber JAR.
Secondly, you are even explicitly excluding JUnit, so how could you
expect it to be included, even if it was not test-scoped?
> <exclude>junit:junit</exclude>
--
Alexander Kriegisch
https://scrum-master.de
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org