在Maven + Spring 3大型Web应用程序中的Proguard [英] Proguard in a Maven + Spring 3 big Web Application

查看:138
本文介绍了在Maven + Spring 3大型Web应用程序中的Proguard的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力模糊我们正在开发的Web应用程序(我们将允许大客户端在他们的服务器上托管它),在浏览,搜索和尝试很多之后,我无法减少错误的数量我收到:
有7283个未解决的类或接口引用

I have been trying all day to obfuscate the web application we are developing (we are going to allow big clients to host it on their servers) and after surfing, searching and trying a lot I am unable to reduce the number of errors I receive: "there were 7283 unresolved references to classes or interfaces"

我从20K开始,所以我设法得到了一些改进......

I started from 20K so I managed to get some improvements...

这是我正在使用的pom配置:

This is the pom config I am using:

<plugin>
                <groupId>com.github.wvengen</groupId>
                <artifactId>proguard-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>proguard</goal>
                        </goals>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>net.sf.proguard</groupId>
                        <artifactId>proguard-base</artifactId>
                        <version>4.8</version>
                        <scope>runtime</scope>
                    </dependency>
                </dependencies>             
                <configuration>
                    <obfuscate>true</obfuscate>
                    <includeDependency>true</includeDependency>
                    <options>
                        <option>-target 1.6</option>                    
                        <option>-allowaccessmodification</option>
                        <option><![CDATA[
                            -keep public class * {
                                public <init>(...);  
                                public void set*(...); 
                                public void init*(...); 
                                public void close*(...); 
                                public ** get*(...); 
                                public boolean is*(...); 
                                public boolean can*(...); 
                            } 
                            ]]></option>
                        <option><![CDATA[
                            -keepclassmembers class * { 
                                @javax.inject.Inject *; 
                                @javax.inject.Named *; 
                                @org.springframework.beans.factory.annotation.Autowired *; 
                                @org.springframework.beans.factory.annotation.Qualifier *; 
                                @org.springframework.beans.factory.annotation.Value *; 
                                @org.springframework.beans.factory.annotation.Required *;
                            }
                            ]]></option>                            
                        <option>-keep @org.springframework.stereotype.Service class *</option>
                        <option>-keep @org.springframework.stereotype.Controller class * </option>
                        <option>-keep @org.springframework.stereotype.Component class * </option>
                        <option>-keep @org.springframework.stereotype.Repository class *</option>
                    </options>
                    <inFilter>com/proton/**,!com/proton/protocol/**</inFilter>
                    <injar>${build.warname}.${project.packaging}</injar>
                    <outjar>${build.warname}-proguarded.${project.packaging}</outjar>
                    <outputDirectory>${project.build.directory}</outputDirectory>
                    <addMavenDescriptor>false</addMavenDescriptor>
                    <libs>
                        <lib>${java.home}/lib/rt.jar</lib>
                        <lib>${java.home}/lib/jce.jar</lib>                      
                        <lib>${java.home}/lib/jsse.jar</lib>
                    </libs>
                    <proguardVersion>4.8</proguardVersion>
                </configuration>
            </plugin>

结果日志的很大一部分:
https://raw.github.com/gist/3708235/37b4cada40fa4742fd1e3ef0f24efd69fa232b28/Proguard

And a big part of the result log: https://raw.github.com/gist/3708235/37b4cada40fa4742fd1e3ef0f24efd69fa232b28/Proguard

似乎至少有很大一部分错误来自春季图书馆,我相信我必须通过遵守规则来修复一些动态调用,但如果有人可以帮助所有人,我会很高兴这个错误。

It seems that at least a big chunk of the errors are from spring libraries, I am sure I must work a lot with keep rules to fix some dynamic calls but I will be great if someone could help with all this errors.

推荐答案

我忘了我打开了这个问题,这是我们现在正在使用的设置:

I forgot I had this question open, this is the setup we are using right now:

<plugin>
            <groupId>com.github.wvengen</groupId>
            <artifactId>proguard-maven-plugin</artifactId>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>proguard</goal>
                    </goals>
                </execution>
            </executions>
            <dependencies>
                <dependency>
                    <groupId>net.sf.proguard</groupId>
                    <artifactId>proguard-base</artifactId>
                    <version>4.8</version>
                    <scope>runtime</scope>
                </dependency>
            </dependencies>             
            <configuration>
                <obfuscate>true</obfuscate>
                <includeDependency>true</includeDependency>
                <options>
                    <option>-target 1.6</option>                    
                    <option>-dontoptimize</option>
                    <option>-keepdirectories</option>
                    <option>-renamesourcefileattribute SourceFile</option>
                    <option>-keepparameternames</option>
                    <option>-keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,*Annotation*,EnclosingMethod</option>
                    <option><![CDATA[
                        -keep public class com.proton.commons.** { public protected *; }
                        ]]></option>    
                            <!-- Here comes a lot of interface packages, public classes, etc as the last one -->    
                    <option><![CDATA[
                        -keepclassmembers enum * {
                            public static **[] values();
                            public static ** valueOf(java.lang.String);
                        }                       
                        ]]></option>        
                    <option><![CDATA[
                        -keepclassmembers class * { 
                            @org.springframework.beans.factory.annotation.Autowired *; 
                            @org.springframework.beans.factory.annotation.Qualifier *; 
                            @org.springframework.beans.factory.annotation.Value *; 
                            @org.springframework.beans.factory.annotation.Required *;
                            @org.springframework.context.annotation.Bean *;
                            @javax.annotation.PostConstruct *;
                            @javax.annotation.PreDestroy *;
                            @org.aspectj.lang.annotation.AfterReturning *;
                            @org.aspectj.lang.annotation.Pointcut *;
                            @org.aspectj.lang.annotation.AfterThrowing *;
                            @org.aspectj.lang.annotation.Around *;
                        }
                        ]]></option>                            
                    <option>-keep @org.springframework.stereotype.Service class *</option>
                    <option>-keep @org.springframework.stereotype.Controller class * </option>
                    <option>-keep @org.springframework.stereotype.Component class * </option>
                    <option>-keep @org.springframework.stereotype.Repository class *</option>
                    <option>-keep @org.springframework.cache.annotation.EnableCaching class *</option>
                    <option>-keep @org.springframework.context.annotation.Configuration class *</option>
                 <!-- Custom annotation -->
                    <option>-keep @com.proton.ks.aop.ProtonLogging class *</option>
                    <option>-keep @org.aspectj.lang.annotation.Aspect class *</option>
                    <option>-keep @java.lang.annotation.Retention class *</option>
                    <option>-keep @java.lang.annotation.Target class *</option>
                    <option>-dontwarn javax.**</option>
                    <option>-dontnote com.proton.ks.preferences.PreferenceFactory</option>
                </options>
                <addMavenDescriptor>false</addMavenDescriptor>
                <libs>
                    <lib>${java.home}/lib/rt.jar</lib>
                    <lib>${java.home}/lib/jce.jar</lib>                      
                    <lib>${java.home}/lib/jsse.jar</lib>
                    <lib>${java.home}/lib/ext/sunjce_provider.jar</lib>
                </libs>
                <proguardVersion>4.8</proguardVersion>
            </configuration>
        </plugin>

这篇关于在Maven + Spring 3大型Web应用程序中的Proguard的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆