Alex Rivera | Logout

Maven, Proguard and assembly issues

Asked 2009-05-19T03:32:23.983
19

I'm trying to get Maven working with ProGuard.

What I want to achieve is the following:

  • Run ProGuard over my source files and produce obfuscated classes

  • Create a manifest file that references the main class so that I can execute it as a jar

  • Unpack all of the associated library jars and create one huge jar containing them all. This file should only contact .class and .xml files only.

  • Assemble them into .zip and tar.gz files that include various README.txt files and so on.

So far I've got something like this:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.2</version>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>com.class.path.MainClass</mainClass>
                    </manifest>
                </archive>
                <includes>
                    <include>**/*.class</include>
                    <include>**/*.xml</include>
                </includes>
            </configuration>
        </plugin>

        <plugin>
            <groupId>com.pyx4me</groupId>
            <artifactId>proguard-maven-plugin</artifactId>
            <configuration>
                <options>
                    <option>-allowaccessmodification</option>
                </options>
                <obfuscate>true</obfuscate>
                <injar>classes</injar>
                <outjar>${project.build.finalName}.jar</outjar>
                <outputDirectory>${project.build.directory}</outputDirectory>
                <proguardInclude>src/main/assembly/proguard.conf
Edit
Report

1 Answer

11

Here is the configuration that had worked for me

<plugin>
    <groupId>com.pyx4me</groupId>
    <artifactId>proguard-maven-plugin</artifactId>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>proguard</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <obfuscate>true</obfuscate>
        <options>
            <option>-allowaccessmodification</option>
            <option>-keep public class com.class.path.MainClass { 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>
</plugin>

The final jar is the finalName-small.jar

answered 2009-05-20T07:51:02.100

Your Answer