Working maven obfuscate example

本秂侑毒 提交于 2019-12-03 10:16:45

问题


I just want to obfuscate simple maven java app. I use maven-proguard-plugin. All classes main/java must be obfuscated. I try different configs with no luck. The last is:

    <build>
    <plugins>
        <plugin>
            <groupId>com.github.wvengen</groupId>
            <artifactId>proguard-maven-plugin</artifactId>
            <version>2.0.6</version>
            <dependencies>
                <dependency>
                    <groupId>net.sf.proguard</groupId>
                    <artifactId>proguard-base</artifactId>
                    <version>4.10</version>
                    <scope>runtime</scope>
                </dependency>
            </dependencies>
            <executions>
               <execution>
                   <phase>package</phase>
                   <goals><goal>proguard</goal></goals>
               </execution>
            </executions>
            <configuration>
                <proguardVersion>4.10</proguardVersion>
                <options>
                    <option>-keep class *{*;}</option>
                </options>
                <libs>
                    <lib>${java.home}/lib/rt.jar</lib>
                </libs>
            </configuration>
        </plugin>
    </plugins>
</build>

result - all classes exist in target jar, but not obfuscated, jad decompiles it well. How to do obfuscate right? Can't understand - is just obfuscate all source are very uncommon task? All other plugins works out of the box like a charm. Why i must type some strange options in this one? I spent a day already. I want convention over configuration! :)


回答1:


Maven such a great thing :). You can make what you want and even not understand, what you want. After i read the introduction, i understand that it's a stupid question. Keep parameter is very important. Here pass in the public methods which must not changed. Of course plugin can't undestand by itself what methods you plan to use. Correct config:

<build>
    <plugins>
        <plugin>
            <groupId>com.github.wvengen</groupId>
            <artifactId>proguard-maven-plugin</artifactId>
            <version>2.0.6</version>
            <dependencies>
                <dependency>
                    <groupId>net.sf.proguard</groupId>
                    <artifactId>proguard-base</artifactId>
                    <version>4.10</version>
                </dependency>
            </dependencies>
            <executions>
               <execution>
                   <phase>package</phase>
                   <goals><goal>proguard</goal></goals>
               </execution>
            </executions>
            <configuration>
                <proguardVersion>4.10</proguardVersion>
                <options>
                    <option>-keep public class myapp.Main{public static void main(java.lang.String[]);}</option>
                </options>
                <libs>
                    <lib>${java.home}/lib/rt.jar</lib>
                    <lib>${java.home}/lib/jce.jar</lib>
                </libs>
            </configuration>
        </plugin>
    </plugins>
</build>


来源:https://stackoverflow.com/questions/21275911/working-maven-obfuscate-example

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!