-
-
Save BigSully/07af6d3bc8213e0c26a90c832e8b8ce6 to your computer and use it in GitHub Desktop.
Obfuscate a jar with Gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
buildscript { | |
repositories { | |
mavenCentral() | |
} | |
dependencies { | |
classpath 'net.sf.proguard:proguard-gradle:5.3.3' | |
} | |
} | |
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); \ | |
}' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment