Obfuscating Custom Gradle Plugin

Asked by At

I'm writing a custom gradle plugin. I have main class which extends org.gradle.api.Plugin<org.gradle.api.Project> and 4 other utility classes. The plugin is working as expected. Now, I want to Obfuscate the code before upload it to jcenter. I have tried following approach.


import proguard.gradle.ProGuardTask

apply plugin: 'groovy'

task proguard(type: ProGuardTask, dependsOn: 'jar') {

    injars "$buildDir/libs/plugin-1.0-SNAPSHOT.jar"
    outjars "$buildDir/libs/plugin-1.0-obfuscated.jar"

    configuration 'proguard-rules.pro'


-printmapping out.map
-renamesourcefileattribute SourceFile
-keepattributes Exceptions, InnerClasses, Signature, Deprecated, SourceFile, LineNumberTable, EnclosingMethod

-keep class com.myplugin.MyCustomPlugin {
    public *;

If I use above configuration, the obfuscated jar contains only MyCustomPlugin class. My other utility classes did not include in the obfuscated jar.

If I use

-keep class com.myplugin.** {
    public *;

All the classes are included in the obfuscated jar. But, Obfuscation didn't happen for the utility classes.

AFAIK, Classes with -keep class attribute will not be obfuscated and all other classes must be obfuscated. IDK, Why it is not working.

Did I miss any parameters in proguard gradle task or proguard-rules.pro?

0 Answers