maven-shade-plugin : exclude a dependency and all its transitive dependencies

electrotype :

Using maven-shade-plugin, is there a way to exclude a dependency (which is not "provided") and all its transitive dependencies?

For example :

<dependencies>

    <dependency>
        <groupId>com.example</groupId>
        <artifactId>some-artifact</artifactId>
        <version>1.0.0-SNAPSHOT</version>
    </dependency>

    ... other dependencies

</dependencies>

and 1)

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>2.3</version>
            <configuration>
                <artifactSet>
                    <includes>
                        <include>*:*</include>
                    </includes>
                    <excludes>
                        <exclude>com.example:some-artifact</exclude>
                    </excludes>
                </artifactSet>
            </configuration>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

or 2)

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>2.3</version>
            <configuration>
                <artifactSet>
                    <includes>
                        <include>*:*</include>
                    </includes>
                </artifactSet>
                <filters>
                    <filter>
                        <artifact>com.example:some-artifact</artifact>
                        <excludes>
                            <exclude>**</exclude>
                        </excludes>
                    </filter>
                </filters>
            </configuration>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

Those don't work. All the transitive dependencies of com.example:some-artifact are added to the final jar. Note that I don't want to set the scope of com.example:some-artifact to "provided".

dcsohl :

Run "shade" from within a profile, and mark your dependency as provided only in that profile. For example:

<profiles>
    <profile>
        <id>shadeProfile</id>
        <dependencies>
            <dependency>
                <groupId>com.example</groupId>
                <artifactId>some-artifact</artifactId>
                <version>1.23</version>
                <scope>provided</scope>
            </dependency>
        </dependencies>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-shade-plugin</artifactId>
                    <version>2.3</version>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>shade</goal>
                            </goals>
                            <configuration>
                                <shadedClassifierName>shaded</shadedClassifierName>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

When you run mvn -PshadeProfile package it will treat your dependency as provided (and thus omit its dependencies), and it will use the classifier "shaded" so you can use this as a dependency in other modules.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Exclude transitive dependency of Gradle plugin

From Java

exclude transitive shaded dependency in maven

From Java

How to exclude a direct dependency of a Maven Plugin

From Java

Shade all dependencies of another dependency (hibernate) into jar

From Java

Maven dependency management for plugin dependencies

From Java

Why does a dependency with scope "provided" hide transitive dependencies in Maven?

From

What is a transitive Maven dependency?

From

Exclude all transitive dependencies of a single dependency

From Java

Maven install transitive dependencies

From Dev

Maven dependency plugin copy jar with dependencies

From Dev

Transitive AAR dependencies in Maven

From Dev

How to exclude transitive dependency in Sbt ( in context of assembly plugin )?

From Dev

How can I exclude all transitive dependencies of a library in SBT?

From Dev

What does this "all*.exclude" means in Gradle transitive dependency?

From Dev

Maven exclude dependency of transitive dependency

From Dev

Maven transitive dependency not loaded

From Dev

How to avoid maven shade plugin from including transitive dependencies from 'test-jar' types?

From Dev

maven-dependency-plugin can't exclude test-scope dependencies

From Dev

Maven exclude transitive dependency of a transitive dependency

From Dev

Is there a maven plugin that will verify conflicting versions of transitive dependencies?

From Dev

maven exclude plugin in dependency

From Dev

Maven assembly plugin: how to include provided dependencies of transitive dependencies

From Dev

Maven unpack-dependencies of a plugin dependency

From Dev

How to exclude transitive dependencies with scope provided with maven-assembly-plugin?

From Dev

Maven shader plugin doesn't shade dependencies in artifact

From Dev

maven-shade-plugin won't include dependencies

From Dev

Maven shade plugin - Jar and dependencies

From Dev

Maven shade plugin with JDA

From Dev

Exclude persistence.xml file from transitive Maven dependency

Related Related

  1. 1

    Exclude transitive dependency of Gradle plugin

  2. 2

    exclude transitive shaded dependency in maven

  3. 3

    How to exclude a direct dependency of a Maven Plugin

  4. 4

    Shade all dependencies of another dependency (hibernate) into jar

  5. 5

    Maven dependency management for plugin dependencies

  6. 6

    Why does a dependency with scope "provided" hide transitive dependencies in Maven?

  7. 7

    What is a transitive Maven dependency?

  8. 8

    Exclude all transitive dependencies of a single dependency

  9. 9

    Maven install transitive dependencies

  10. 10

    Maven dependency plugin copy jar with dependencies

  11. 11

    Transitive AAR dependencies in Maven

  12. 12

    How to exclude transitive dependency in Sbt ( in context of assembly plugin )?

  13. 13

    How can I exclude all transitive dependencies of a library in SBT?

  14. 14

    What does this "all*.exclude" means in Gradle transitive dependency?

  15. 15

    Maven exclude dependency of transitive dependency

  16. 16

    Maven transitive dependency not loaded

  17. 17

    How to avoid maven shade plugin from including transitive dependencies from 'test-jar' types?

  18. 18

    maven-dependency-plugin can't exclude test-scope dependencies

  19. 19

    Maven exclude transitive dependency of a transitive dependency

  20. 20

    Is there a maven plugin that will verify conflicting versions of transitive dependencies?

  21. 21

    maven exclude plugin in dependency

  22. 22

    Maven assembly plugin: how to include provided dependencies of transitive dependencies

  23. 23

    Maven unpack-dependencies of a plugin dependency

  24. 24

    How to exclude transitive dependencies with scope provided with maven-assembly-plugin?

  25. 25

    Maven shader plugin doesn't shade dependencies in artifact

  26. 26

    maven-shade-plugin won't include dependencies

  27. 27

    Maven shade plugin - Jar and dependencies

  28. 28

    Maven shade plugin with JDA

  29. 29

    Exclude persistence.xml file from transitive Maven dependency

HotTag

Archive