Sometimes we need to exclude a few classes/packages from the the final product build. For example, we need to cherry pick some latest changes and apply them back to an old product deployed with older JVM. If some of the new changes depend on a third party library (for example Guava), you need to make sure the library can be compiled by the old Java.
Normally there are two ways to accomplish this. One way is to modify the library and make it backward-compatible to the old Java (for example Guava jdk5backport). Another way is to remove the unused classes from the library. You don’t need to physically remove those classes to generate a customized reference jar. Instead you can tell maven to read the original jar, exclude classes based on a defined blacklist, then re-package it into a new jar.
How to figure out which classes can be excluded? I normally do it manually, sometimes with the help of some class dependency tools (Class Dependency Analyzer CDA). Occasionally I also use maven shade plugin to make my life easier, especially when in the situation without refection code or servlet code.