Proguard Maven 插件不使用指定的 Proguard 版本
Posted
技术标签:
【中文标题】Proguard Maven 插件不使用指定的 Proguard 版本【英文标题】:Proguard Maven Plugin Doesn't Use The Specified Proguard Version 【发布时间】:2021-10-30 20:35:28 【问题描述】:Proguard Maven 插件未使用指定的 proguard 版本,因此我收到以下错误:(Can't process class [com/sun/javafx/charts/ChartLayoutAnimator.class] (Unsupported class version number [54.0] (maximum 52.0, Java 1.8)))
如果您知道如何强制插件使用更新的版本,请告诉我。
pom.xml
<plugin>
<groupId>com.github.wvengen</groupId>
<artifactId>proguard-maven-plugin</artifactId>
<version>2.0.14</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>proguard</goal>
</goals>
<configuration>
<injar>$project.build.finalName-jar-with-dependencies.jar</injar> <!-- make sure to obfuscate the jar with dependencies -->
<proguardVersion>6.2.2</proguardVersion>
<options>
<option>-allowaccessmodification</option>
<option>-dontoptimize</option>
<option>-dontshrink</option>
<option>-dontnote</option>
<option>-keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,LocalVariable*Table,*Annotation*,Synthetic,EnclosingMethod</option>
<option>-flattenpackagehierarchy ''</option>
<option>-dontwarn</option> <!-- added option to ignore com.sun missing classes -->
<option>-keepattributes Signature</option>
<!--
<option>-keepclasseswithmembers public class com.javafx.main.Main, obfuscationexample.ObfuscationExample public static void main(java.lang.String[]); </option>
-->
<option>-keep public class com.myproject.** *; </option>
<option>-keepclassmembernames class * @javafx.fxml.FXML *; </option>
</options>
<libs>
<lib>$java.home/lib/rt.jar</lib>
<lib>$java.home/lib/jfxrt.jar</lib>
</libs>
</configuration>
</execution>
</executions>
</plugin>
<dependencies>
<dependency>
<groupId>net.sf.proguard</groupId>
<artifactId>proguard-base</artifactId>
<version>6.2.2</version>
<scope>runtime</scope>
</dependency>
</dependencies>
【问题讨论】:
【参考方案1】:事实证明,您必须在打开配置之前关闭执行元素。
<plugin>
<groupId>com.github.wvengen</groupId>
<artifactId>proguard-maven-plugin</artifactId>
<version>2.0.14</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>proguard</goal>
</goals>
</execution>
</executions>
<configuration>
<injar>$project.build.finalName-jar-with-dependencies.jar
</injar> <!-- make sure to obfuscate the jar with dependencies -->
<proguardVersion>6.2.2</proguardVersion>
<options>
<option>-allowaccessmodification</option>
<option>-dontoptimize</option>
<option>-dontshrink</option>
<option>-dontnote</option>
<option>-keepattributes
Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,LocalVariable*Table,*Annotation*,Synthetic,EnclosingMethod
</option>
<option>-flattenpackagehierarchy ''</option>
<option>-dontwarn</option> <!-- added option to ignore com.sun missing classes -->
<option>-keepattributes Signature</option>
<!--
<option>-keepclasseswithmembers public class com.javafx.main.Main, obfuscationexample.ObfuscationExample public static void main(java.lang.String[]); </option>
-->
<option>-keep public class com.myproject.** *; </option>
<option>-keepclassmembernames class * @javafx.fxml.FXML *; </option>
</options>
</configuration>
<dependencies>
<dependency>
<groupId>net.sf.proguard</groupId>
<artifactId>proguard-base</artifactId>
<version>6.2.2</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</plugin>
【讨论】:
是否有任何其他要求需要考虑才能正确运行?当我使用插件时没有任何反应。没有生成文件。 @chitgoks 很多事情可能出错了,我建议通过在 mvn 命令后添加“-X”标志来调试它以运行插件。它会打印出详细的日志。以上是关于Proguard Maven 插件不使用指定的 Proguard 版本的主要内容,如果未能解决你的问题,请参考以下文章
在构建“maven-plugin”包时如何使用 Proguard 混淆?
原创解决Maven ProGuard不混淆局部变量的问题,以及如何使用混淆好的包