Maven with Proguard

Asked

Viewed 622 times

4

Well someone could explain to me how I can use Proguard in the Maven build to obfuscate the web project (War) in the direct deploy for Jetty?

<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>
    <groupId>br.com.female</groupId>
    <artifactId>projeto-web</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.3</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <fork>true</fork>
                    <executable>${JAVA_HOME}/bin/javac.exe</executable>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <configuration>
                    <scanIntervalSeconds>5</scanIntervalSeconds>
                    <httpConnector>
                        <port>8081</port>
                    </httpConnector>
                </configuration>
            </plugin>   

            <plugin>
                <groupId>com.github.wvengen</groupId>
                <artifactId>proguard-maven-plugin</artifactId>
                <executions>
                   <execution>
                       <phase>package</phase>
                       <goals><goal>proguard</goal></goals>
                   </execution>
                </executions>
                <configuration>
                    <options>
                        <option>-allowaccessmodification</option>
                        <option>-keep public class * extends java.applet.Applet { *; }</option>
                    </options>
                    <libs>
                        <lib>C:/Program Files/Java/jre1.8.0_60/lib/rt.jar</lib>
                    </libs>
                </configuration>
            </plugin>                   
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.36</version>
        </dependency>       
    </dependencies>
</project>

There are some errors like [proguard] Error: The output jar is empty. Did you specify the proper '-keep' options? and the [ERROR] Failed to execute goal com.github.wvengen:proguard-maven-plugin:2.0.11:proguard (default) on project projeto-web: Obfuscation failed (result=1) -> [Help 1]

1 answer

1

Use the proguard-maven-plugin. Documentation can be found here.

You should apply the process on the jar, before mounting the War. You will need something like the code below, but adapted to your project:

<build>
    <plugins>
        <plugin>
            <groupId>com.github.wvengen</groupId>
            <artifactId>proguard-maven-plugin</artifactId>
            <executions>
               <execution>
                   <phase>package</phase>
                   <goals><goal>proguard</goal></goals>
               </execution>
            </executions>
            <configuration>
                <options>
                    <option>-allowaccessmodification</option>
                    <option>-keep public class * extends java.applet.Applet { *; }</option>
                </options>
                <libs>
                    <lib>${java.home}/lib/rt.jar</lib>
                </libs>
            </configuration>
        </plugin>
    </plugins>
</build>
  • @Lucyestela Edit your question and post your current plugin configuration.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.