ProGuard + Spring Boot + Maven Plugin
伙计们,我正在尝试使用 proguard-maven-plugin 混淆 .jar 应用程序。
当我尝试执行混淆过程时,我收到错误消息,指出存在意外的类。
我正在使用 Spring Boot 1.4.1.RELEASE 和 Proguard Maven 插件 2.0.13。
这是我的 proguard.conf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | -injars /workspace/base/target/test-1.0.0.jar -libraryjars /Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/jre/lib/rt.jar -dontshrink -dontoptimize -dontobfuscate -dontusemixedcaseclassnames -keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,LocalVariable*Table,*Annotation*,Synthetic,EnclosingMethod -adaptresourcefilenames **.properties -adaptresourcefilecontents **.properties,META-INF/MANIFEST.MF -dontpreverify -verbose -keepclasseswithmembers public class * { public static void main(java.lang.String[]); } -keepclassmembers enum * { public static **[] values(); public static ** valueOf(java.lang.String); } -keep class * extends java.beans.BeanInfo -keep class * { void set*(***); void set*(int,***); boolean is*(); boolean is*(int); *** get*(); *** get*(int); } -assumenosideeffects public class java.lang.System { public static long currentTimeMillis(); static java.lang.Class getCallerClass(); public static int identityHashCode(java.lang.Object); public static java.lang.SecurityManager getSecurityManager(); public static java.util.Properties getProperties(); public static java.lang.String getProperty(java.lang.String); public static java.lang.String getenv(java.lang.String); public static java.lang.String mapLibraryName(java.lang.String); public static java.lang.String getProperty(java.lang.String,java.lang.String); } |
pom.xml 文件。我只是通过插件通知配置。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | <plugin> <groupId>com.github.wvengen</groupId> proguard-maven-plugin</artifactId> <version>2.0.13</version> <executions> <execution> <phase>package</phase> <goals> <goal>proguard</goal> </goals> </execution> </executions> <configuration> <obfuscate>false</obfuscate> <outFilter>**/BOOT-INF/classes/ **.class</outFilter> <proguardInclude>${basedir}/proguard.conf</proguardInclude> <outputDirectory>${project.build.directory}</outputDirectory> <injar>${project.build.finalName}.jar</injar> <outjar>${project.build.finalName}-min.jar</outjar> </configuration> </plugin> |
但是,在执行过程中,我的应用程序中的所有类都会得到以下返回。
1 2 3 | Warning: class [BOOT-INF/classes/br/com/base/BaseApplication.class] unexpectedly contains class [br.com.base.BaseApplication] Warning: class [BOOT-INF/classes/br/com/base/controller/CaixaController.class] unexpectedly contains class [br.com.base.controller.CaixaController] [...] |
以及 ProGuard 的最终输出。 PS:所有类都在
1 2 3 4 5 6 7 | Warning: there were 97 classes in incorrectly named files. You should make sure all file names correspond to their class names. The directory hierarchies must correspond to the package hierarchies. (http://proguard.sourceforge.net/manual/troubleshooting.html#unexpectedclass) If you don't mind the mentioned classes not being written out, you could try your luck using the '-ignorewarnings' option. Please correct the above warnings first. |
谁能想象我可以尝试的任何替代方案?
谢谢。
为了解决这个问题,我确保更改了 pom.xml 中插件的顺序。 proguard 插件应该放在第一位,然后是 spring boot 插件。
此外,请确保您在 spring boot 配置中指定了
我的插件配置来自 pom.xml:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | <project ...> .... <plugin> <groupId>com.github.wvengen</groupId> proguard-maven-plugin</artifactId> <executions> <execution> <phase>package</phase> <goals> <goal>proguard</goal> </goals> </execution> </executions> <configuration> <proguardInclude>${basedir}/proguard.conf</proguardInclude> <libs> <lib>${java.home}/lib/rt.jar</lib> <lib>${java.home}/lib/jce.jar</lib> </libs> </configuration> </plugin> <plugin> <groupId>org.springframework.boot</groupId> spring-boot-maven-plugin</artifactId> <executions> <execution> <goals> <goal>repackage</goal> </goals> <configuration> <start-class>org.springframework.boot.loader.JarLauncher</start-class> </configuration> </execution> </executions> </plugin> ... |