将另一个依赖项(hibernate)的所有依赖项隐藏到 jar 中

Shade all dependencies of another dependency (hibernate) into jar

我想自动将 Hibernate 核心的所有依赖项隐藏到我的主 jar 中,而不是显式定义它们(因为这似乎变成了追逐鹅)。

我不能把所有东西都放在我的 jar 中,因为不需要其他依赖项,这会使我的 jar 变得不必要地大。

是否可以让 maven 自动屏蔽您的顶级依赖项之一的所有依赖项?

Shade 插件支持选择性 inclusion, exclusion, filtering and minimization of a jar。这应该可以解决问题。

您可以将您不想隐藏的依赖项的范围设置为 'provided',这将向 Maven 标记该库在运行时 provided/assumed 可用。

您的其余依赖项,它们要么没有指定范围,要么具有 'compile' 范围,应该是您的 jar 需要阴影的那些。

然后在你的 pom 中使用类似的东西:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>3.2.3</version>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>shade</goal>
            </goals>
        </execution>
    </executions>
</plugin>