Using Proguard for JDK 1.7 with Maven
Given that you have following scenario:
|photo by Tim Cooper|
- a project based on a maven build
- using the proguard plugin
- with jdk 1.6
and you want to upgrade to jdk 1.7 for whatever reasons (maybe this one), you may encounter following problem:
[proguard] Error: Can't read [/Library/Java/JavaVirtualMachines/jdk1.7.0_06.jdk/Contents/Home/jre/lib/rt.jar] (Can't process class [WrapperGenerator$1.class] (Unsupported version number [51.0] for class format))
It seems like proguard has some problems with the class version number.
Great. What to do? Why me? Again?
After some googling you'll start to wonder why the proguard maven plugin uses an rather old proguard binary itself (remember: the maven-proguard-plugin is just a "starter script" for giving an independent proguard main jar file the appropriate parameters).
You'll find that on the web page of the maven-proguard-plugin there is a section which states that you can provide a different proguard version number. I thought this would solve my issues, so I followed the instructions like told and .... nothing happened. The plugin is still using the proguard version 4.3 for obfuscating code.
There has been some modularization in more artifacts:
|newer versions of proguard don't seem to in the maven central repository.|
Ok, proguard artifact itself is here until 4.4, then there are several other with 4.8 which is at the time of writing the most up to date proguard version.
This change of packaging may well be the reason that the described way to use another proguard version doesn't work as promised (?):
maven-proguard-plugin source code ("the mojo").
(As it seems there is already a patch but the proguard maven plugin isn't published yet, at least not in maven central.)
To make a long story short, this rather innocent looking project comes to the rescue. Together with following configuration it will happily use the proguard 4.8 binary, at least it worked for me.
<build> <plugin> <groupId>com.github.wvengen</groupId> <artifactId>proguard-maven-plugin</artifactId> <version>2.0.5</version> <dependencies> <dependency> <groupId>net.sf.proguard</groupId> <artifactId>proguard-base</artifactId> <version>4.8</version> <scope>runtime</scope> </dependency> </dependencies> <executions> <execution> <phase>package</phase> <goals> <goal>proguard</goal> </goals> </execution> </executions> <configuration> <proguardVersion>4.8</proguardVersion> .... <!-- your configuration goes here --> </configuration> </plugin> </build>
Pay attention to the different artifact id of the proguard binary. (check also the patch mentioned above).