创建没有依赖项的 Maven Uber Jar

发布于 2025-01-10 00:02:43 字数 2559 浏览 0 评论 0原文

我目前正在尝试从一个包中的多个 jar 创建一个库 jar,这是我无法控制的。

我一直致力于摆脱传递依赖。

库 pom.xml 看起来像这样

<?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>

当我将库作为依赖项添加到项目之一的其他模块时,它工作得很好,但我仍然拥有树中的所有依赖项以及打包到最终产品(war、ear)中。

有没有比将库排除在另一个项目中更好的方法(它就是这样并且不再需要)或者使用一些对我来说似乎有点黑客的本地存储库?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文