Obfuscate Java Jar with dependencies using Maven Proguard Plugin

I started from the most simple Java Maven generated project and added a class that should be obfuscated
There is no obfuscation after
mvn clean install
I attached an archive with the whole Maven / Intellij project
Google Drive zip with Hello World project

the pom looks like that

  <plugins>
<plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <executions>
                <execution>
                    <id>assembly</id>
                    <goals>
                        <goal>single</goal>
                    </goals>
                    <phase>package</phase>
                    <configuration>
                        <descriptorRefs>
                            <descriptorRef>jar-with-dependencies</descriptorRef>
                        </descriptorRefs>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>com.github.wvengen</groupId>
            <artifactId>proguard-maven-plugin</artifactId>
            <version>2.0.8</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals><goal>proguard</goal></goals>
                    <configuration>
                        <injar>${project.build.finalName}-jar-with-dependencies.jar</injar> <!-- make sure to obfuscate the jar with dependencies -->
                        <proguardVersion>5.2</proguardVersion>
                        <options>
                            <option>-allowaccessmodification</option>
                            <option>-dontoptimize</option>
                            <option>-dontshrink</option>
                            <option>-dontnote</option>
                            <option>-dontwarn</option> <!-- added option to ignore com.sun missing classes -->
                            <option>-keepattributes Signature</option>
                            <option>-keep class com.mycompany.MyPlugin { *; }</option>
                        </options>
                        <libs>
                            <lib>${java.home}/lib/rt.jar</lib>
                        </libs>
                        <dependencies>
                            <dependency>
                                <groupId>net.sf.proguard</groupId>
                                <artifactId>proguard-base</artifactId>
                                <version>5.2</version>
                                <scope>runtime</scope>
                            </dependency>
                        </dependencies>
                    </configuration>
                </execution>
            </executions>
        </plugin>

  </plugins>
</pluginManagement>
1 Like

Hi Dorin, Would you mind replacing the Google Drive Zip with a Github project link? For security reasons we don’t encourage non-Github links for downloading on the forums.

We appreciate your understanding, and looking forward to helping you out with this question!