Skip to content

Instantly share code, notes, and snippets.

@lucacesari
Created September 19, 2014 06:55
Show Gist options
  • Save lucacesari/dfe5868e1e6826f0c6d3 to your computer and use it in GitHub Desktop.
Save lucacesari/dfe5868e1e6826f0c6d3 to your computer and use it in GitHub Desktop.
Obfuscate a jar with Gradle
ext {
mainClassName = "foo.bar.buz.mainClass"
basename = "fooBar"
version = "42.0"
}
task obfuscate(type: proguard.gradle.ProGuardTask) {
injars "./build/libs/${basename}-${version}.jar"
outjars "./build/libs/${basename}-${version}-obf.jar"
libraryjars "${System.getProperty('java.home')}/lib/rt.jar"
dontwarn
overloadaggressively
repackageclasses 'foo'
printmapping "./build/libs/${basename}.map"
keep 'class !foo.bar.buz**,!foo.bar.baz.** { *; }'
keepclasseswithmembers "public class ${mainClassName} { \
public static void main(java.lang.String[]); \
}"
keepclassmembers allowshrinking:true, 'enum * { \
public static **[] values(); \
static boolean contains(java.lang.String); \
}'
}
@denzuko
Copy link

denzuko commented Mar 14, 2018

@maru2213 sound like you haven't include proguard as a dependance in your gradle file

@BigSully
Copy link

BigSully commented Sep 9, 2020

Add this line to the beginning of your gradle file. @maru2213

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'net.sf.proguard:proguard-gradle:5.3.3'
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment