Java Code Exclusion for Backporting

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.

Advertisements
This entry was posted in Build, Java, Tool and Debug and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s