Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ProGuard + Maven with Java 7

I'm trying to make ProGuard part of our Maven build process. The problem is that the official Maven plugin is using ProGuard 4.3, which doesn't support Java 7. Is there any easy way to make the plugin use Proguard 4.8 instead?

I've tried specifying the dependency for the plugin but ProGuard seems to have a new structure for Maven-modules (proguard-base, proguard-parent etc) so the plugin can't use any version >4.4. Here's how my current pom looks:

 <plugin>
                <groupId>com.pyx4me</groupId>
                <artifactId>proguard-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>proguard</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <proguardVersion>4.8</proguardVersion>
                    <obfuscate>true</obfuscate>
                    <options>
                        <option>-allowaccessmodification</option>
                        <option>-keep public class com.degoo.ui.ClientBackendStarter { public *; public static *; }</option>
                    </options>
                    <injar>${project.build.finalName}.jar</injar>
                    <outjar>${project.build.finalName}-small.jar</outjar>
                    <outputDirectory>${project.build.directory}</outputDirectory>
                    <libs>
                        <lib>${java.home}/lib/rt.jar</lib>
                        <lib>${java.home}/lib/jsse.jar</lib>
                    </libs>
                    <addMavenDescriptor>false</addMavenDescriptor>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>net.sf.proguard</groupId>
                        <artifactId>proguard</artifactId>
                        <version>4.8</version>
                        <scope>runtime</scope>
                    </dependency>
                </dependencies>
            </plugin>

Any suggestions?

like image 678
Yrlec Avatar asked Jun 07 '12 09:06

Yrlec


1 Answers

I use the proguard-maven-plugin from com.github.wvengen. Note the different groupId. That way I can use the latest proguard-base artifact 5.0. Both are in Maven Central. Here's how the proguard-base portion in my pom.xml looks right now:

Parent pom.xml:

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>com.github.wvengen</groupId>
                <artifactId>proguard-maven-plugin</artifactId>
                <version>2.0.8</version>
                <dependencies>
                    <dependency>
                        <groupId>net.sf.proguard</groupId>
                        <artifactId>proguard-base</artifactId>
                        <version>5.0</version>
                        <scope>runtime</scope>
                    </dependency>
                </dependencies>
            </plugin>
[...]

Here's the rest from my child pom.xml, but you probably want to modify that:

 <build>
    <plugins>
        <plugin>
            <groupId>com.github.wvengen</groupId>
            <artifactId>proguard-maven-plugin</artifactId>
            <executions>
                <execution>
                    <id>process-classes-with-proguard</id>
                    <phase>process-classes</phase>
                    <goals>
                        <goal>proguard</goal>
                    </goals>
                    <configuration>
                        <maxMemory>256m</maxMemory>
                        <injar>classes</injar>
                        <libs>
                            <lib>${rt.jar.path}</lib>
                            <lib>${jsse.jar.path}</lib>
                        </libs>
                        <obfuscate>true</obfuscate>
                        <attach>true</attach>
                        <addMavenDescriptor>false</addMavenDescriptor>
                        <proguardInclude>${project.basedir}/proguard.conf</proguardInclude>
                    </configuration>
                </execution>
            </executions>
        </plugin>

UPDATE: For my Android projects I'm not using a dedicated Proguard plugin like proguard-maven-plugin since the android-maven-plugin handles the ProGuard obfuscation itself, and is integrated better into the build process for Android.

like image 156
Bernd S Avatar answered Sep 30 '22 09:09

Bernd S