ProGurad可以进行代码混淆和优化。
<plugin>
<groupId>com.github.wvengen</groupId>
<artifactId>proguard-maven-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals><goal>proguard</goal></goals>
</execution>
</executions>
<configuration>
<proguardVersion>6.0.3</proguardVersion>
<injar>${project.build.finalName}.jar</injar>
<outjar>${project.build.finalName}.jar</outjar>
<obfuscate>true</obfuscate>
<proguardInclude>proguard.conf</proguardInclude>
<libs>
<!-- Include main JAVA library required.-->
<lib>${java.home}/lib/rt.jar</lib>
<!-- Include crypto JAVA library if necessary.-->
<lib>${java.home}/lib/jce.jar</lib>
</libs>
</configuration>
<dependencies>
<dependency>
<groupId>net.sf.proguard</groupId>
<artifactId>proguard-base</artifactId>
<version>6.0.3</version>
</dependency>
</dependencies>
</plugin>
proguard.conf 配置proguard处理逻辑,以下是一份配置示例,放置在项目目录
#保留不被混淆
#保留包中所有
-keep class com.xxx.client.**{*;}
-keep class com.xxx.entity.**{*;}
#保留类中所有
-keep class com.xxx.FtdPacket{*;}
-keep class com.xxx.FtdPacketFactory{*;}
-keepclassmembers enum * { *; }
-keepclassmembers public class * extends java.lang.annotation.Annotation{*;}
-keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,*Annotation*,EnclosingMethod ##对异常、注解信息在runtime予以保留,不然影响springboot启动
#保留所有目录结构(使用反射时要注意)
-keepdirectories
#忽略警告
-ignorewarnings
#混淆时应用侵入式重载
-overloadaggressively
#优化时允许访问并修改有修饰符的类和类的成员
#-allowaccessmodification
#确定统一的混淆类的成员名称来增加混淆
-useuniqueclassmembernames
#不打印note信息
-dontnote
#不缩进
-dontshrink
#不优化(优化会改变代码访问限制,需要谨慎)
-dontoptimize
#不警告
#-dontwarn
#为类成员分配唯一的名字
-useuniqueclassmembernames
#匹配与类名称相同的字符常量,并进行混淆
-adaptclassstrings
#不使用大小写混合类名
#-dontusemixedcaseclassnames