Exclude unused parts of dependencies from jar (Mav

2019-03-24 16:30发布

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?

2条回答
forever°为你锁心
2楼-- · 2019-03-24 16:47

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.

查看更多
一纸荒年 Trace。
3楼-- · 2019-03-24 16:54

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.

查看更多
登录 后发表回答