0

We are building a maven based project. Now I am trying use the shade plugin to generate a runnable jar file.

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer   implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.myCompany.mainClass</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<pluginRepositories>
<pluginRepository>
  <id>apache maven</id>
  <url>http://repo1.maven.org/maven2/org/apache/maven/plugins</url>
</pluginRepository>
</pluginRepositories>

When I run maven build, it give many warning like: [WARNING] We have a duplicate org/slf4j/impl/StaticMDCBinder.class in C:\Users\maven.repo\company\org\slf4j\slf4j-nop\1.6.2\slf4j-nop-1.6.2.jar

It seems every dependency gets duplicate. Could someone give me some suggestion about this? Thank you very much and happy thanksgiving.

lucky_start_izumi
  • 2,511
  • 13
  • 41
  • 61

1 Answers1

2

Using maven dependency:tree command you can print and check all logging dependencies, possible some of them contains duplicated classes, like in this case http://maven.40175.n5.nabble.com/Duplicate-class-warnings-when-using-shade-plugin-td121854.html Then use exclude tag to remove redundant from them Exclude all transitive dependencies of a single dependency

Also I would recommend to use maven-assembly-plugin which attach jar with dependencies as additional artifact under configurable classifier instead of replacing an original one (like in your configuration):

            <artifactId>maven-assembly-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>attached</goal>
                    </goals>
                    <phase>package</phase>
                    <configuration>
                        <descriptorRefs>
                            <descriptorRef>jar-with-dependencies</descriptorRef>
                        </descriptorRefs>
                        <archive>
                            <manifest>
                                <mainClass>com.myCompany.mainClass</mainClass>
                            </manifest>
                        </archive>
                    </configuration>
                </execution>
            </executions>
Community
  • 1
  • 1
Andriy Plokhotnyuk
  • 7,883
  • 2
  • 44
  • 68