Scala runnable JAR的ProGuard流程

时间:2015-03-31 21:38:06

标签: java eclipse scala proguard executable-jar

我正在尝试缩小(以及混淆和优化)简单的Scala程序,该程序包含在可运行的JAR中。

我在Scala IDE中创建了2个项目:简单的Scala程序和执行此Scala程序的Java包装器。然后我使用“导出”生成了可运行的JAR - > “Runnable JAR文件”Eclipse实用程序,“将所需的库提取到生成的JAR”选项。

之后我尝试使用ProGuard缩小器(GUI版本)缩小JAR,但它失败并出现以下注释和警告:output at pastebin.com

有没有正确的方法呢?

1 个答案:

答案 0 :(得分:1)

一个好的起点是使用建议的参数在http://proguard.sourceforge.net/manual/examples.html#scala的scala项目上运行proguard。这些基本选项可能会解决大多数警告,例如:

-dontwarn scala.**

-keepclasseswithmembers public class * {
    public static void main(java.lang.String[]);
}

-keep class * implements org.xml.sax.EntityResolver

-keepclassmembers class * {
    ** MODULE$;
}

-keepclassmembernames class scala.concurrent.forkjoin.ForkJoinPool {
    long eventCount;
    int  workerCounts;
    int  runControl;
    scala.concurrent.forkjoin.ForkJoinPool$WaitQueueNode syncStack;
    scala.concurrent.forkjoin.ForkJoinPool$WaitQueueNode spareStack;
}

-keepclassmembernames class scala.concurrent.forkjoin.ForkJoinWorkerThread {
    int base;
    int sp;
    int runState;
}

-keepclassmembernames class scala.concurrent.forkjoin.ForkJoinTask {
    int status;
}

-keepclassmembernames class scala.concurrent.forkjoin.LinkedTransferQueue {
    scala.concurrent.forkjoin.LinkedTransferQueue$PaddedAtomicReference head;
    scala.concurrent.forkjoin.LinkedTransferQueue$PaddedAtomicReference tail;
    scala.concurrent.forkjoin.LinkedTransferQueue$PaddedAtomicReference cleanMe;
}

我也使用这些:

-keepattributes Signature,*Annotation*
-dontobfuscate

// turn some optimizations off when using -dontobfuscate
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*,!code/allocation/variable,!class/unboxing/enum

// lots of other classes, e.g. logging
-keep public class ch.qos.logback.** { *;}
-keep public class org.slf4j.** { *;}    

如果您希望自动化它,您还可以使用sbt-proguard插件在sbt中运行proguard。如果要将proguard输出合并到可执行jar或包中,则可以将proguard输出输入sbt-assemblysbt-native-packager