Exclude unused parts of dependencies from jar (Maven)

只谈情不闲聊 提交于 2019-12-21 03:32:35

问题


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.

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


回答1:


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.

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




回答2:


It's not possible to include only classes which are used. But you can exclude dependencies from your depencies to reduce the JAR size. Only drawback: you need to know what you can exclude and what not.



来源:https://stackoverflow.com/questions/6957760/exclude-unused-parts-of-dependencies-from-jar-maven

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!