Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven: exclude dependency from shade plugin

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>
like image 244
VB_ Avatar asked Mar 12 '14 12:03

VB_


People also ask

How do I exclude a specific version of a dependency in Maven?

Multiple transitive dependencies can be excluded by using the <exclusion> tag for each of the dependency you want to exclude and placing all these exclusion tags inside the <exclusions> tag in pom. xml. You will need to mention the group id and artifact id of the dependency you wish to exclude in the exclusion tag.

How do I remove dependency reduced POM?

You can avoid having it created by setting createDependencyReducedPom to false. e.g. If you turn it off, then the thing you build will still have all the merged-in dependencies listed as dependencies.

What is a dependency reduced POM?

The dependency-reduced-pom. xml removes transitive dependencies which are already in your shaded jar. This prevents consumers from pulling them in twice.

What is uber jar Maven?

An uber-JAR—also known as a fat JAR or JAR with dependencies—is a JAR file that contains not only a Java program, but embeds its dependencies as well. This means that the JAR functions as an “all-in-one” distribution of the software, without needing any other Java code.


2 Answers

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>
like image 154
blackbuild Avatar answered Oct 19 '22 08:10

blackbuild


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

like image 43
Daidipya Avatar answered Oct 19 '22 07:10

Daidipya