Question

I've seen next string after mvn clean install

Including com.sun.jersey.contribs:jersey-multipart:jar:1.5 in the shaded jar

Problem: I can't make it not shaded even I've added exlusion for maven-shade-plugin (see code below)

My maven-shade-plugin:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>2.1</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <filters>
                            <filter>
                                <artifact>*:*</artifact>
                                <excludes>
                                    <exclude>META-INF/*.SF</exclude>
                                    <exclude>META-INF/*.DSA</exclude>
                                    <exclude>META-INF/*.RSA</exclude>
                                </excludes>
                            </filter>
                        </filters>
                        <artifactSet>
                            <excludes>
//Here ==>                      <exclude>com.sun.jersey.contribs:jersey-multipart:jar</exclude>
                            </excludes>
                        </artifactSet>
                        <transformers>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <manifestEntries>
                                    <Main-Class>Main</Main-Class>
                                    <Build-Number>123</Build-Number>
                                </manifestEntries>
                            </transformer>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                <resource>META-INF/spring.handlers</resource>
                            </transformer>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                <resource>META-INF/spring.schemas</resource>
                            </transformer>
                        </transformers>
                    </configuration>
                </execution>
            </executions>
        </plugin>
Was it helpful?

Solution

According to http://maven.apache.org/plugins/maven-shade-plugin/shade-mojo.html, your exclusion syntax is wrong:

Artifacts to include/exclude from the final artifact. Artifacts are denoted by composite identifiers of the general form groupId:artifactId:type:classifier. ... For convenience, the syntax groupId is equivalent to groupId:*:*:*, groupId:artifactId is equivalent to groupId:artifactId:*:* and groupId:artifactId:classifier is equivalent to groupId:artifactId:*:classifier.

So either use com.sun.jersey.contribs:jersey-multipart:*:jar or com.sun.jersey.contribs:jersey-multipart for your exclusion.

               <artifactSet>
                  <excludes>
                     <exclude>com.sun.jersey.contribs:jersey-multipart</exclude>
                   </excludes>
               </artifactSet>

OTHER TIPS

Add scope tag in dependency tag with value as 'provided'. It will exclude that dependency. Similar to below dependency

For anyone, who made a lot of steps to exclude some transitive artifact from your fat jar and it still presented, there may be two causes:

  1. This dependency is transitive for other dependency, not that one, where you've made exclusion. Thus you need to add exclusion tag somewhere else (if your exclusion is located in <dependencies> section, not plugin-level).

mvn dependency:tree is very useful for these searches.

  1. These dependency classes comes to your jar straight from some dependency artifact as ordinary classes, not transitive dependency.

There is some chance that one of dependencies of your project represents fat jar. Certain classes which you want to exclude comes to your project as ordinary classes, not transitive dependency. Thus Maven unable to exclude it. Also this is a reason that Maven’s provided scope is not working (classes still presented in your jar).

More details here: https://mchesnavsky.tech/maven-dependency-exclusion-not-working/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top