从jar(Maven)排除依赖项的未使用部分 [英] Exclude unused parts of dependencies from jar (Maven)

查看:697
本文介绍了从jar(Maven)排除依赖项的未使用部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个小型项目,其中包含一些重量级的依赖项(例如Spring),其中我们仅使用较小的部分.因此,当打包所有依赖项时,即使对于两类服务器,我们得到的JAR也重达几兆字节.这似乎不必要.

We have a small project with some heavy-weight dependencies (e.g. Spring) of which we only use small parts. Therefore, the JAR we get when packing with all dependencies weighs several megabytes, even for out two-class-server. This seems unnecessary.

有没有一种方法可以将JAR程序集限制为实际使用的(类)文件?

Is there a way to restrict JAR assembly to actually used (class) files?

推荐答案

您可以使用 maven-shade-plugin 来创建具有依赖项的Jar(您的项目和依赖项已合并到一个大jar中),同时限制了添加到该jar中的类或软件包.请参阅包含/排除页面以供参考.

You can use the maven-shade-plugin to create a Jar-with-dependencies (your project and the dependencies merged into one big jar) while limiting the classes or packages that are added to that jar. See the includes / excludes page for reference.

如果您不想手动指定需要包含的内容,也许可以使用一种方法来集成 ProGuard 与您的构建.

If you don't want to manually specify what needs to be included, perhaps there is a way to integrate ProGuard with your build.

这篇关于从jar(Maven)排除依赖项的未使用部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆