Exclude unused parts of dependencies from jar (Maven)

Raphael picture Raphael · Aug 5, 2011 · Viewed 8.5k times · Source

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?

Answer

Sean Patrick Floyd picture Sean Patrick Floyd · Aug 5, 2011

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.