Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to obfuscate fat Scala Jar with Proguard and SBT

I've managed to obfuscate my Scala code but I can't figure out how to run obfuscation against a jar file that is built by sbt assembly step. Or at least how to build a fat jar during the proguard step. I found that there is a injar argument for proguard but I have no clue how to apply it to build.sbt. Can someone please point me to how I can do this.

UPD Actually the JAR that is built by Proguard contains only obfuscated classes and not a single class from those that are ignored by Proguard.

like image 628
Zyoma Avatar asked Sep 23 '16 07:09

Zyoma


1 Answers

To run a Proguard obfuscation against a jar file that was built by assembly task previously you should override inputs setting in build.sbt:

proguardInputs in Proguard := Seq((assemblyOutputPath in assembly).value)

This would specify your fat jar as a single input for Proguard. Also you probably want to modify the input libraries that are used for obfuscation. Here is an example of how to exclude all the libraries:

proguardLibraries in Proguard := Seq()

Finally disable input filter since you have only one source of classes:

proguardInputFilter in Proguard := { file => None }

The setting above is required because Proguard will exclude META-INF/MANIFEST.MF file by default. Also merge step is no longer required since assembly task already performed this step:

proguardMerge in Proguard := false

And finally add assembly dependency to your Proguard task:

(ProguardKeys.proguard in Proguard) <<= (ProguardKeys.proguard in Proguard).dependsOn(assembly)
like image 135
Zyoma Avatar answered Oct 04 '22 02:10

Zyoma