maven插件proguard混洗代码

 Java代码混淆工具ProGuard是比较流行的,它主要的功能包含:缩减代码、优化代码、混淆代码,而且这三部分代码都是可以配置开启/关闭的。下面将介绍使用maven,快速集成。

//pom中添加
<plugin>
                <groupId>com.github.wvengen</groupId>
                <artifactId>proguard-maven-plugin</artifactId>
                <version>2.0.7</version>
                <executions>
                    <execution>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>proguard</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <injar>classes</injar>
                    <attach>true</attach>
                    <proguardInclude>${basedir}/proguard.conf</proguardInclude>
                    <attachArtifactClassifier>pg</attachArtifactClassifier>
                    <!-- attach 的作用是在 install 与 deploy 时将生成的 pg 文件也安装与部署 -->
                    <outjar>${project.build.finalName}-pg</outjar>
                    <options> <!-- 详细配置方式参考 ProGuard 官方文档 -->
                        <!--<option>-dontobfuscate</option>-->
                        <option>-ignorewarnings</option>
                        <!--忽略所有告警-->
                        <option>-dontshrink</option>
                        <!--不做 shrink -->
                        <option>-dontoptimize</option>
                        <!--不做 optimize -->
                        <option>-dontskipnonpubliclibraryclasses</option>
                        <option>-dontskipnonpubliclibraryclassmembers</option>

                        <option>-repackageclasses com.kxtx.pg</option>
                        <!--平行包结构(重构包层次),所有混淆的类放在 pg 包下-->
                        <option>-keep class **.package-info</option>
                        <option>-keepattributes Exceptions,InnerClasses,Signature,SourceFile,LineNumberTable,*Annotation*</option>

                        <!-- 以下为 Keep,哪些内容保持不变,因为有一些内容混淆后(a,b,c)导致反射或按类名字符串相关的操作失效 -->
                    </options>
                    <libs>
                        <lib>${java.home}/lib/rt.jar</lib>
                    </libs>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>net.sf.proguard</groupId>
                        <artifactId>proguard-base</artifactId>
                        <version>5.2.1</version>
                    </dependency>
                </dependencies>
            </plugin>

在工程的根目录中(与src同级目录),调整proguard.conf配置

# ----------------------------------  
#   混淆时不会产生形形色色的类名   
#   -dontusemixedcaseclassnames  
# ----------------------------------  
-dontusemixedcaseclassnames

-keepparameternames
-keep class com.kxtx.utils.** {public <methods>;}
-keep class com.kxtx.batch.** {public <methods>;}
-keep class com.kxtx.cache.** {public <methods>;}
-keepnames public class com.kxtx.controller.*
-keep class com.kxtx.controller.* {public <methods>;}
-keep class com.kxtx.controls.** {public <methods>;}
-keep class com.kxtx.core.utils.** {public <methods>;}
-keepnames public class com.kxtx.exception.*
-keep class com.kxtx.init.** {public <methods>;}
-keep class com.kxtx.java.beans.** {public <methods>;}
-keep class com.kxtx.mybatis.** {public <methods>;}
-keepclassmembers enum com.kxtx.mybatis.annotation.CommonFieldType { *;}
-keep class com.kxtx.security.** {public <methods>;}
-keep class com.kxtx.spring.beans.** {public <methods>;}
-keep class com.kxtx.util.** {public <methods>;}
-keep class com.kxtx.validation.domain.** {public <methods>;}
-keep class com.kxtx.validation.domain.support.* {protected <methods>;}
-keep class com.kxtx.validation.annotation.** {public <methods>;}
-keep class com.kxtx.validation.dao.** {public <methods>;}
-keep class com.kxtx.validation.service.** {public <methods>;}
-keep class com.kxtx.validation.web.advice.** {public <methods>;}
-keep class com.kxtx.validation.utils.** {public <methods>;}
-keep class com.kxtx.validation.validator.AbstractCustomValidator {protected <methods>;}
-keep class com.kxtx.web.filter.** {public <methods>;}
-keep class com.kxtx.web.handler.** {public <methods>;}
-keep class com.kxtx.web.session.** {public <methods>;}
-keep class com.kxtx.web.* {public <methods>;}
-keep class com.kxtx.web.vo.* {public <methods>;}
-keepclassmembers class * {
    public static <fields>;
}
-keep class com.kxtx.mybatis.service.impl.BaseServiceImpl{
    public protected *;
}
-keep class com.kxtx.areas.** {public <methods>;}
-keep class com.kxtx.areas.model.* { private <fields>;}
-keep class com.kxtx.utils.UserUtils { *;}
-keep class com.kxtx.web.session.UserInfoAttributesConverter{ *;}
-keep class com.kxtx.converter.** {public <methods>;}
-keep class com.kxtx.vo.UniqueVo { *;}-keep class om.kxtx.security.function.authentication.** {public <methods>;}

 

已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 书香水墨 设计师:CSDN官方博客 返回首页