Plugin Obfuscation and Gradle

Discussion in 'Spigot Plugin Development' started by mrkirby153, Jun 8, 2015.

  1. I've been trying for the past hour to get proguard and gradle to work together and obfuscate my jar. However, when running the obufscate task, proguard can't resolve any bukkit classes. I've tried setting libraryjars to just about anything imaginable and yet it still does not work correctly. Why?

    My Build.gradle
    Code (Text):
    buildscript {
        repositories {
            maven {
                name = "Quarxel"
                url = "http://repo.sandwichnetwork.tk/nexus/content/groups/quarxel/"
                credentials {
                    username project.repositoryUsername
                    password project.repositoryPassword
                }
            }
        }
        dependencies {
            classpath group: 'me.mrkirby153.quarxel', name: 'QuarxelManager', version: '1.0-SNAPSHOT'
            classpath group: 'org.proguard', name: 'proguard', version: '5.2.1'
        }
    }

    apply plugin: 'quarxel'

    repositories {
        mavenCentral();
        maven {
            name = "Quarxel"
            url = "http://******/nexus/content/repositories/quarxel/"
            credentials {
                username project.repositoryUsername
                password project.repositoryPassword
            }
        }
        maven {
            name = "Spigot"
            url = "https://hub.spigotmc.org/nexus/content/groups/public/"
        }
        maven {
            name = "Sonatype"
            url = "https://oss.sonatype.org/content/repositories/snapshots/"
        }
    }

    dependencies {
        compile name: "spigot-api", group: "org.spigotmc", version: "1.8.3-R0.1-SNAPSHOT"
        compile name: "spigot", group: "org.spigotmc", version: "1.8.3-1"
    }

    quarxel {
        serverLocation '/testServer'
        if (project.hasProperty("serverArgs")) {
            serverArgs project.serverArgs
        } else {
            serverArgs '-Xmx1G'
        }
    }

    /** Proguard Obfuscation */
    task testProguard(type: proguard.gradle.ProGuardTask) {
        injars jar.archivePath
        outjars "out.jar"
        printmapping "Core.map"
        flattenpackagehierarchy "me.mrkirby153.quarxelnetwork"
        adaptresourcefilenames '**.yml'
        libraryjars project.proguardLibs
    }
    testProguard.dependsOn jar
     
  2. Try setting -libraryjar to an absolute path .. and I've honestly used proguard after I produce my artifacts instead of trying to have it integrated with my build process. You might just want to do that to avoid the problem all together.

    And where are you setting the arguments for proguard? You can configure the task straight from gradle: http://proguard.sourceforge.net/manual/gradle.html (edit: nevermind, you didn't have the full text out at the time of writing)

    edit: you have libraryjars set to progaurd, not Bukkit.

    Also, If you're selling a premuim plugin, making your source code difficult to understand doesn't protect you from anything, it just annoys people that might want to know the internal workings of your plugin.

    You're also (technically) obligated to have the original, compilable source available for everyone who has a copy of your binary (see GPLv3 on Bukkit/Craftbukkit, it applies to libraries and plugins).
     
    #2 Jarcode, Jun 8, 2015
    Last edited: Jun 8, 2015
  3. I'm sorry if I didn't make it clear enough but the project.proguardLibs is a property set in my grade.properties file. It just pointed to a location so I could test. At this point, it might just be easier to do as you said before and proguard after building the jar.