ProGuard optimizer and obfuscator in multi-module maven projects

ProGuard is a tool that processes java .class files and generates smaller, faster and harder to read bytecode.
I had to use it for a single module in a multi-module maven project, and found no documentation for that, thus I describe the steps here.

In the module that should be obfuscated, a build step has to be configured in maven. The important thing here is the configuration with „<attach>true“, so that the obfuscated file is exported to the repository and hence can be used by other modules.

                        <option>-keep public class package.ParameterObject{ public *;}</option>
                        <option>-keep public class package.Implementation{public static void
                        <option>-optimizationpasses 4</option>

If you run the build, you can see that two artifacts are generated now by this module: A module-1.0.0-SNAPSHOT.jar that has the same content as before, and a module-1.0.0-SNAPSHOT-small.jar that contains the small and obfuscated code. You can pick another name instead of „small“ by specifying the „attachArtifactClassifier“-property in the configuration.

How do you use this obfuscated code from another module in the project? Pretty easy, the small-suffix (or however you named it) can be used as the classifier in the maven-dependency:


Run the build and look at the packaged artifact (for example a .war), it will no longer contain the clear bytecode, but only the obfuscated library.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.