Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove unused methods/classes from dependencies

Tags:

java

maven

Many libraries contain much more functions than I need. If I shade them into my jar, the jar contains 80% code which is never used.

Is there a way to remove any unused methods & classes from the dependencies I shade into my jar?

like image 380
Florian Avatar asked May 27 '17 18:05

Florian


1 Answers

Unless you have extremely good integration tests I advise to be really careful about this idea.

Far too often frameworks might use reflection here or there - and no tool can determine through static analysis which parts of the code will be called via reflection.

Beyond that: how many megabytes are we talking here? Keep in mind that a Java SE installation contains many thousand classes which you will never be using.

What I mean: is this a real problem or a assumed one? Did a customer complain about too many dependencies? Is there anything that causes real trouble for you? Then, and only then you should be looking into reducing the "jar content".

Finally: keep in mind that you are the one who created those dependencies in the first place! So, when you are worried about the number of items pulled in for your product - maybe you first check if there are ways to reduce the direct dependencies of your product. Instead of going with a "too large" list and that idea to reduce jar contents as suggested in the question.

like image 89
GhostCat Avatar answered Oct 15 '22 10:10

GhostCat