英文:
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:
<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>
答案2
得分: 0
The Shade插件支持对jar包进行选择性的包含、排除、过滤和最小化。这应该能解决问题。
英文:
The Shade plugin supports selective inclusion, exclusion, filtering and minimization of a jar. This should do the trick.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论