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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With