'Create Maven Uber Jar without dependencies

I'm currently trying to create a library jar from multiple jars that come in one bundle which is out of my control.

I'm stuck at getting rid of the transitive dependencies.

Library pom.xml looks like this

<?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/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>root-pom</artifactId>
        <groupId>foo</groupId>
        <version>1</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>library</artifactId>
    <packaging>jar</packaging>

    <dependencies>
        <dependency>
            <groupId>out-of-my-control</groupId>
            <artifactId>out-of-my-control</artifactId>
            <version>1</version>
            <type>pom</type>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.2.4</version>
                <executions>
                    <execution>
                        <id>shade</id>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <filters>
                                <filter>
                                    <excludes>
                                        <exclude>META-INF/*.SF</exclude>
                                        <exclude>META-INF/*.DSA</exclude>
                                        <exclude>META-INF/*.RSA</exclude>
                                    </excludes>
                                </filter>
                            </filters>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

When I add the library as dependency to one of the projects other modules it works just fine but I still have all the dependencies in the tree as well as packaged into the final product (war, ear).

Is there a better way than excluding the library into another project which is how it was and not wanted anymore or using some local repository which seems a bit hacky to me?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source