Thi*_*ira 3 proguard maven spring-boot
伙计们,我正在尝试使用 proguard-maven-plugin 来混淆 .jar 应用程序。
当我尝试执行混淆过程时,我收到错误消息,指出存在意外的类。
我正在使用 Spring Boot 1.4.1.RELEASE 和 Proguard Maven 插件 2.0.13。
这是我的proguard.conf
-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);
}
Run Code Online (Sandbox Code Playgroud)
pom.xml文件。我只是通过插件通知配置。
<plugin>
<groupId>com.github.wvengen</groupId>
<artifactId>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>
Run Code Online (Sandbox Code Playgroud)
但是,在执行过程中,我得到应用程序中所有类的以下返回值。
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]
[...]
Run Code Online (Sandbox Code Playgroud)
以及ProGuard的最终输出。PS:所有类都在BOOT-INF/classes目录中
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.
Run Code Online (Sandbox Code Playgroud)
谁能想象我可以尝试的任何替代方案吗?谢谢。
为了解决这个问题,我确保更改了 pom.xml 中插件的顺序。proguard 插件应该首先出现,然后是 spring boot 插件。
此外,请确保您已<goal>repackage</goal>在 Spring Boot 配置中指定。通过正确的顺序和指定的重新打包目标,混淆/优化/您配置的任何内容都将发生并生成一个 jar。然后 spring boot 插件会将该 jar 重新打包为可执行文件,一切都应该可以正常工作。
我的 pom.xml 插件配置:
<project ...>
....
<plugin>
<groupId>com.github.wvengen</groupId>
<artifactId>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>
<artifactId>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>
...
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5569 次 |
| 最近记录: |