赞
踩
最近公司需要向甲方交付源码,想要对项目代码进行混淆,以提高代码阅读难度,提高源码安全性。这个任务就交到了我身上,不负众望也是弄出来了,分享一下。
- <build>
- <finalName>${project.artifactId}</finalName>
- <defaultGoal>compile</defaultGoal>
- <plugins>
- <plugin>
- <groupId>com.github.wvengen</groupId>
- <artifactId>proguard-maven-plugin</artifactId>
- <version>2.6.0</version>
- <executions>
- <execution>
- <!--打包的时候开始混淆-->
- <phase>package</phase>
- <goals>
- <!--混淆-->
- <goal>proguard</goal>
- </goals>
- </execution>
- </executions>
-
- <configuration>
- <injar>${project.build.finalName}.jar</injar>
- <!--输出的jar-->
- <outjar>${project.build.finalName}.jar</outjar>
- <outputDirectory>${project.basedir}/target</outputDirectory>
- <!--是否混淆-->
- <obfuscate>true</obfuscate>
- <!--是否允许进行代码混淆时将依赖放入临时文件夹(防止依赖太多或者依赖层级过深超出windows命令最大长度报错)-->
- <putLibraryJarsInTempDir>true</putLibraryJarsInTempDir>
- <!--是否允许进行代码混淆时生成临时配置文件-->
- <generateTemporaryConfigurationFile>true</generateTemporaryConfigurationFile>
- <!--proguard官网推荐-->
- <inLibsFilter>!META-INF/**,!META-INF/versions/9/**.class</inLibsFilter>
-
- <options>
- <!--jdk版本-->
- <option>-target 1.8</option>
- <!--不做收缩-->
- <option>-dontshrink</option>
- <!--不做代码优化-->
- <option>-dontoptimize</option>
- <!--查找和替换在代码中以字符串形式引用的类名(处理代码中com.example.MyClass格式类名)-->
- <option>-adaptclassstrings</option>
- <!--proguard官网推荐-->
- <option>-dontskipnonpubliclibraryclasses</option>
- <option>-dontskipnonpubliclibraryclassmembers</option>
- <option>-dontusemixedcaseclassnames</option>
- <option>-useuniqueclassmembernames</option>
- <option>-keepparameternames</option>
- <option>-keeppackagenames</option>
- <option>-keepattributes *Annotation*, Signature, Exceptions, InnerClasses, EnclosingMethod, LineNumberTable, LocalVariableTable, LocalVariableTypeTable, RuntimeVisibleAnnotations, RuntimeInvisibleAnnotations, RuntimeVisibleParameterAnnotations, RuntimeInvisibleParameterAnnotations, MethodParameters</option>
- <!--保持目录结构-->
- <option>-keepdirectories</option>
- <option>-keepclassmembers enum * { *; }</option>
- <option>-keepclassmembers public class * { void set*(***); *** get*(); }</option>
- <option>-keep class com.fw.formland.backend.entity.**{*;}</option>
- <option>-keep class com.fw.formland.backend.mapper.**{*;}</option>
- <option>-keep class com.fw.formland.backend.model.**{*;}</option>
- <option>-keep class com.fw.formland.backend.mapper.** { *; }</option>
- <option>-keepclassmembers class com.fw.formland.backend.mapper.** { *; }</option>
-
- <option>
- -keep class * {
- @org.springframework.beans.factory.annotation.Value *;
- @javax.annotation.PostConstruct *;
- @javax.annotation.PreDestroy *;
- @org.springframework.scheduling.annotation.Async *;
- @org.springframework.context.annotation.Bean *;
- @org.springframework.context.annotation.Configuration *;
- @org.springframework.stereotype.Component *;
- }
- </option>
- <option>-keepclasseswithmembers public class *{
- public static void main(java.lang.String[]); }
- </option>
- </options>
- <libs>
- <lib>${java.home}/lib/rt.jar</lib>
- <lib>${java.home}/lib/jsse.jar</lib>
- </libs>
- <!--多模块项目中,如果有别的模块应用了当前模块的代码,则需将其它模块也进行混淆处理并以代码的形式放到最后的输出文件中,而不是以jar包的形式-->
- <assembly>
- <inclusions>
- <inclusion>
- <groupId>com.fw.formland</groupId>
- <artifactId>bpm-extend</artifactId>
- </inclusion>
- <inclusion>
- <groupId>com.fw.formland</groupId>
- <artifactId>formland_base</artifactId>
- </inclusion>
- </inclusions>
- </assembly>
- </configuration>
- </plugin>
-
- <plugin>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-maven-plugin</artifactId>
- <executions>
- <execution>
- <id>repackage</id>
- <goals>
- <goal>repackage</goal>
- </goals>
- </execution>
- </executions>
- <!--多模块项目中,如果有别的模块应用了当前模块的代码,在做完上述assembly的配置之后,需要在最后输出文件的依赖中排除掉assembly中配置的两个依赖项-->
- <configuration>
- <excludeGroupIds>com.fw.formland</excludeGroupIds>
- </configuration>
- </plugin>
- </plugins>
- </build>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。