I'm trying to shrink (and also to obfuscate and to optimize) simple Scala program which packed into runnable JAR.
I created 2 projects in Scala IDE: simple Scala program and Java wrapper which executes this Scala program. Then I generated runnable JAR using "Export" -> "Runnable JAR file" Eclipse utility with "Extract required libraries into generated JAR" option.
After that I tried to shrink JAR with ProGuard shrinker (GUI version) but it failed with the following notes and warnings: output at pastebin.com.
Is there any correct way to do this?
A good place to start is with the suggested parameters for running proguard on a scala project at http://proguard.sourceforge.net/manual/examples.html#scala. Those basic options will probably solve most of those warnings, e.g.:
-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;
}
I also use these:
-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.** { *;}
If you're looking to automate it, you can also run proguard in sbt with the sbt-proguard plugin. The proguard output can then be fed into sbt-assembly or sbt-native-packager if you want to incorporate it into an executable jar or a package.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With