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.desil...@nrc-cnrc.gc.ca<mailto:alain.desil...@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

Reply via email to