原 java使用proguard对代码进行混淆
版权声明:本文为博主原创文章,请尊重他人的劳动成果,转载请附上原文出处链接和本声明。
本文链接:https://www.91mszl.com/zhangwuji/article/details/1478
<build>
<plugins>
<plugin>
<groupId>com.github.wvengen</groupId>
<artifactId>proguard-maven-plugin</artifactId>
<version>2.6.1</version>
<executions>
<execution>
<phase>package</phase><!-- 混淆时刻,这里是打包的时候混淆 -->
<goals><goal>proguard</goal></goals><!-- 使用插件的混淆功能 -->
</execution>
</executions>
<configuration>
<proguardVersion>6.2.2</proguardVersion>
<obfuscate>true</obfuscate><!--是否混淆-->
<proguardInclude>${project.basedir}/src/main/resources/proguard.cfg</proguardInclude><!-- 加载配置文件 -->
<injar>${project.build.finalName}.jar</injar><!-- 对什么东西进行加载 -->
<outjar>${project.build.finalName}.jar</outjar><!-- class混淆后输出的jar包 或 文件夹 -->
<outputDirectory>${project.build.directory}</outputDirectory><!-- 输出目录 -->
<libs>
<lib>${java.home}/lib/rt.jar</lib><!-- Include main JAVA library required -->
<lib>${java.home}/lib/jce.jar</lib><!-- Include crypto JAVA library if necessary -->
<lib>${java.home}/lib/jsse.jar</lib>
</libs>
</configuration>
<dependencies>
<dependency>
<groupId>net.sf.proguard</groupId>
<artifactId>proguard-base</artifactId>
<version>6.2.2</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
# 指定不警告尚未解决的引用和其他问题
-dontwarn
# JDK目标版本1.8
-target 1.8
# 不做收缩(删除注释、未被引用代码)
-dontshrink
# 不做优化(变更代码实现逻辑)
-dontoptimize
# 混淆时不使用大小写混合,混淆后的类名为小写
-dontusemixedcaseclassnames
# 不去忽略非公共的库类
-dontskipnonpubliclibraryclasses
# 指定不跳过包可见的库类成员(字段和方法)默认情况下,proguard在解析库类时会跳过包可见的库类成员。当我们确实引用了包可见的类成员时,需要设置此项
-dontskipnonpubliclibraryclassmembers
# 确定统一的混淆类的成员名称来增加混淆
-useuniqueclassmembernames
# 优化时允许访问并修改有修饰符的类和类的成员
-allowaccessmodification
# 不混淆所有包名
# -keeppackagenames
#混淆时是否记录日志
#-verbose
# 需要保持的属性:异常,注解等
-keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,LocalVariable*Table,*Annotation*,Synthetic,EnclosingMethod
# spring相关的注解,不要混淆
-keepclassmembers class * {
@org.springframework.** *;
@javax.annotation.PostConstruct *;
@javax.annotation.PreDestroy *;
}
# spring相关的注解,不要混淆
-keepclassmembers class * {
@org.springframework.beans.factory.annotation.Autowired <fields>;
@org.springframework.beans.factory.annotation.Autowired <methods>;
}
# 不混淆所有包含Component等注解的类
-keep @org.springframework.stereotype.Component class * {*;}
-keep @org.springframework.stereotype.Service class * {*;}
-keep @org.springframework.web.bind.annotation.RestController class * {*;}
-keep @org.springframework.context.annotation.Configuration class * {*;}
# 不混淆所有的set/get方法
-keepclassmembers public class * {void set*(***);*** get*();}
# 启动类不能混淆
-keep public class com.gaia.sjzch5.SjzcH5PepsiApplication {
public static void main(java.lang.String[]);
}
注意:proguard.cfg放在项目的resources目录下
代码混淆后的截图如下:
2024-03-08 09:11:25 阅读(514)
名师出品,必属精品 https://www.91mszl.com
博主信息