将另一个依赖项(hibernate)的所有依赖项都打包到jar中。

huangapple go评论76阅读模式
英文:

Shade all dependencies of another dependency (hibernate) into jar

问题

我想自动将Hibernate核心的所有依赖项都融入我的主JAR文件中,而不需要显式定义它们(因为这似乎只会变成一场苦苦追逐的游戏)。

我不能只是将一切都融入我的JAR文件中,因为其他依赖项是不需要的,这会使我的JAR文件变得不必要地庞大。

是否可以让Maven自动将您的顶级依赖项之一的所有依赖项都融入?

英文:

I'd like to automatically shade all the dependencies of Hibernate core into my main jar, without defining them explicitly (As this just seems to become a goose chase).

I can't just shade everything into my jar, as other dependencies are not needed and it would make my jar unnecessarily huge.

Is it possible to get maven to automatically shade all of the dependencies of one of your top-level dependencies?

答案1

得分: 1

You can set the scope of the dependencies you don't want shaded to 'provided' and that'll flag to Maven that the library is provided/assumed available at runtime.

The rest of your dependencies, which either don't have a specified scope or have the 'compile' scope, should be those that your JAR needs to have shaded.

Then just use something similar to this in your 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>
英文:

You can set the scope of the dependencies you don't want shaded to 'provided' and that'll flag to maven that the library is provided/assumed available at runtime.

The rest of your dependencies, which either don't a specified scope or have the 'compile' scope, should be those that your jar needs to have shaded.

Then just use something similar to this in your pom:

&lt;plugin&gt;
    &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
    &lt;artifactId&gt;maven-shade-plugin&lt;/artifactId&gt;
    &lt;version&gt;3.2.3&lt;/version&gt;
    &lt;executions&gt;
        &lt;execution&gt;
            &lt;phase&gt;package&lt;/phase&gt;
            &lt;goals&gt;
                &lt;goal&gt;shade&lt;/goal&gt;
            &lt;/goals&gt;
        &lt;/execution&gt;
    &lt;/executions&gt;
&lt;/plugin&gt;

答案2

得分: 0

The Shade插件支持对jar包进行选择性的包含、排除、过滤和最小化。这应该能解决问题。

英文:

The Shade plugin supports selective inclusion, exclusion, filtering and minimization of a jar. This should do the trick.

huangapple
  • 本文由 发表于 2020年8月11日 05:07:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/63348041.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定