Won't compile .jar

Hello,

I’m trying to compile my project (it’s a plugin in a .jar) it’s the first time I use ProGuard but when I compile I get this in the console:

My configuration is basically the default for ProGuard.

plugins {
    java
    id("com.github.johnrengelman.shadow") version ("7.1.2")
}

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("com.guardsquare:proguard-gradle:7.1.0")
    }
}

group = "simpleblockregen"
version = "0.1.8-SNAPSHOT"

repositories {
    mavenCentral()
    maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/")
    maven("https://oss.sonatype.org/content/groups/public/")
    maven("https://maven.enginehub.org/repo/")
    maven("https://repo.unnamed.team/repository/unnamed-public/")
    maven("https://repo.codemc.io/repository/nms/")
    maven("https://nexus.mrcubee.net/repository/minecraft/")
    maven("https://mvn.lumine.io/repository/maven-public/")
    maven("https://jitpack.io")
    maven("https://repo.extendedclip.com/content/repositories/placeholderapi/")
}

dependencies {
    implementation("team.unnamed.common:commons-error:2.0.0-SNAPSHOT")
    implementation("me.fixeddev:commandflow-bukkit:0.5.0-SNAPSHOT")
    implementation("org.bstats:bstats-bukkit:3.0.0")
    compileOnly("dev.espi:protectionstones:2.8.4")
    compileOnly("org.spigotmc:spigot-api:1.13-R0.1-SNAPSHOT")
    compileOnly("com.sk89q.worldguard:worldguard-bukkit:7.0.3")
    compileOnly("net.Indyuce:MMOItems:6.7.2")
    compileOnly("io.lumine:MythicLib-dist:1.3.1")
    compileOnly("org.projectlombok:lombok:1.18.22")
    compileOnly("com.github.TechFortress:GriefPrevention:16.17.1")
    compileOnly("me.clip:placeholderapi:2.11.1")
    annotationProcessor("org.projectlombok:lombok:1.18.22")
}

tasks {
    java {
        toolchain {
            languageVersion.set(JavaLanguageVersion.of(11))
        }
    }
    withType<JavaCompile> {
        options.encoding = "UTF-8"
    }
    shadowJar {
        delete(file("${project.buildDir}"))
        archiveClassifier.set("")
        relocate("org.bstats", "bstats-bukkit")
        archiveFileName.set("${project.name}-${project.version}.jar")
        minimize()
    }
    build {
        dependsOn(shadowJar)
    }
    processResources {
        filesMatching("plugin.yml") {
            expand("v" to project.version)
        }
    }

}

tasks.register<proguard.gradle.ProGuardTask>("proguard") {
    verbose()

    // Alternatively put your config in a separate file
    // configuration("config.pro")

    // Use the jar task output as a input jar. This will automatically add the necessary task dependency.
    injars(tasks.named("jar"))

    outjars("build/proguard-obfuscated.jar")

    val javaHome = System.getProperty("java.home")
    // Automatically handle the Java version of this build.
    if (System.getProperty("java.version").startsWith("1.")) {
        // Before Java 9, the runtime classes were packaged in a single jar file.
        libraryjars("$javaHome/lib/rt.jar")
    } else {
        // As of Java 9, the runtime classes are packaged in modular jmod files.
        libraryjars(
            // filters must be specified first, as a map
            mapOf("jarfilter" to "!**.jar",
                "filter"    to "!module-info.class"),
            "$javaHome/jmods/java.base.jmod"
        )
    }

    allowaccessmodification()

    repackageclasses("")

    printmapping("build/proguard-mapping.txt")

    keep("""class gradlekotlindsl.App {
                public static void main(java.lang.String[]);
            }
    """)
}

Hi @Skjolberg,

Welcome to the PG community!

Can you share the full stacktrace so we can see the cause for the compilation failure? It was not clear from the screenshot provided.

Thank you!
Jack

I have updated the task with this:

tasks.register<proguard.gradle.ProGuardTask>("proguard") {

    configuration("${buildDir}/proguard.pro")
    injars("${buildDir}/libs/${project.name}-${project.version}.jar")
    outjars("${buildDir}/libs/${rootProject.name}_proguard.jar")
}

And I keep getting this:

My cfg file, practically default, except for injar and outjar.:

#
# This ProGuard configuration file illustrates how to process ProGuard itself.
# Configuration files for typical applications will be very similar.
# Usage:
#     java -jar proguard.jar @proguard.pro
#

-verbose

# Specify the input jars, output jars, and library jars.

#-injars  C:\Users\danie\IdeaProjects\SimpleBlockRegen\build\libs\SimpleBlockRegen-0.0.2-SNAPSHOT.jar
#-outjars C:\Users\danie\IdeaProjects\SimpleBlockRegen\build\libs\SimpleBlockRegen_proguard.jar

# Before Java 9, the runtime classes were packaged in a single jar file.
#-libraryjars <java.home>/lib/rt.jar

# As of Java 9, the runtime classes are packaged in modular jmod files.
-libraryjars <java.home>/jmods/java.base.jmod(!**.jar;!module-info.class)
-libraryjars <java.home>/jmods/java.sql.jmod (!**.jar;!module-info.class)
#-libraryjars <java.home>/jmods/.....

# Write out an obfuscation mapping file, for de-obfuscating any stack traces
# later on, or for incremental obfuscation of extensions.

-printmapping proguard.map

# Don't print notes about reflection in GSON code, the Kotlin runtime, and
# our own optionally injected code.

-dontnote kotlin.**
-dontnote kotlinx.**
-dontnote com.google.gson.**
-dontnote proguard.configuration.ConfigurationLogger

# Preserve injected GSON utility classes and their members.

-keep,allowobfuscation class proguard.optimize.gson._*
-keepclassmembers class proguard.optimize.gson._* {
    *;
}

# Obfuscate class strings of injected GSON utility classes.

-adaptclassstrings proguard.optimize.gson.**

# Allow methods with the same signature, except for the return type,
# to get the same obfuscation name.

-overloadaggressively

# Put all obfuscated classes into the nameless root package.

-repackageclasses ''

# Allow classes and class members to be made public.

-allowaccessmodification

# The entry point: ProGuard and its main method.

-keep public class proguard.ProGuard {
    public static void main(java.lang.String[]);
}

# If you want to preserve the Ant task as well, you'll have to specify the
# main ant.jar.

#-libraryjars /usr/local/java/ant/lib/ant.jar
#-adaptresourcefilecontents proguard/ant/task.properties
#
#-keep,allowobfuscation class proguard.ant.*
#-keepclassmembers public class proguard.ant.* {
#    <init>(org.apache.tools.ant.Project);
#    public void set*(***);
#    public void add*(***);
#}

# If you want to preserve the Gradle task, you'll have to specify the Gradle
# jars.

#-libraryjars /usr/local/java/gradle-4.2.1/lib/plugins/gradle-plugins-4.2.1.jar
#-libraryjars /usr/local/java/gradle-4.2.1/lib/gradle-base-services-4.2.1.jar
#-libraryjars /usr/local/java/gradle-4.2.1/lib/gradle-core-4.2.1.jar
#-libraryjars /usr/local/java/gradle-4.2.1/lib/groovy-all-2.4.12.jar

#-keep public class proguard.gradle.* {
#    public *;
#}

# If you want to preserve the WTK obfuscation plug-in, you'll have to specify
# the kenv.zip file.

#-libraryjars /usr/local/java/wtk2.5.2/wtklib/kenv.zip
#-keep public class proguard.wtk.ProGuardObfuscator

Hi @Skjolberg,

The screenshot you sent says:
"Please correct the warning above"

And, I see warnings referencing certain classes, which can’t be found. There are various reasons for why this might occur. But most likely here, is shrinkage or optimization at play.

Just shooting from the hip here, I would imagine that keeping those classes will prevent the issue here. You can test this theory with a rule like this:
keep class net.shibacraft.simpleblockregen.** {*;}

And if that works, you can fine-tune that more, so that you are only keeping the classes it references in the warnings.

Regardless, without some more information, it’s not fully clear why this is happening. Please send me the full stacktrace by using the following command:
gradle --info --stacktrace clean assembleRelease

If the suggestion above does not solve the issue alone, I will need the stacktrace to further guide you.

It would also be helpful if you can tell me which step is creating this issue, by disabling each step, 1 by 1:

-dontshrink
-dontoptimize
-dontobfuscate

This will you allow to disable each step (1 by 1) determine which step is creating the issue. This will help narrow the investigation so we can be even more precise in our guidance to you. This may take a couple iterations.

Please let me know if anything is not clear.

Kind regards,
Jack

Hello again Jack,

I’ve been quite busy this time, I’ll pass you the build.gradle.kts and the proguard config so you can see how I have it all set up, I just compiled it before and it lets me compile it, but when I decompile the plugin with a program I have, you can see all the code and it doesn’t obfuscate anything.

I also let you know that I’m a beginner in this and I don’t know if I’m doing anything that seems silly and I’m doing it wrong.

Thx

Build.gradle.kts

import java.io.ByteArrayOutputStream


buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("com.guardsquare:proguard-gradle:7.1.1")
    }
}

plugins {
    java
    id("com.github.johnrengelman.shadow") version ("7.1.2")
}

var relocate = "net.shibacraft.simpleblockregen.api.libs"

group = "${project.property("group")}"
version = "${project.property("version")}"

repositories {
    mavenLocal()
    mavenCentral()
    maven("https://mvn.lumine.io/repository/maven-public/")
    maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/")
    maven("https://jitpack.io")
    maven("https://repo.extendedclip.com/content/repositories/placeholderapi/")
    maven("https://repo.alessiodp.com/releases/")
    maven("https://repo.papermc.io/repository/maven-public/")
    maven("https://repo.unnamed.team/repository/unnamed-public/")

}
dependencies {

    implementation(libs.libby)
    compileOnly(libs.kyori)
    compileOnly(libs.paper)
    compileOnly(libs.jsoup)
    //compileOnly(libs.commons)
    compileOnly(libs.commandFlow)
    compileOnly(libs.bStats)
    compileOnly(libs.protectionStones)
    compileOnly(libs.protectionStones)
    compileOnly(libs.worldGuard)
    compileOnly(libs.mmoItems)
    compileOnly(libs.mythicLib)
    compileOnly(libs.lombok)
    compileOnly(libs.griefPrevention)
    compileOnly(libs.placeHolderAPI)
    compileOnly(libs.simplixStorage)
    compileOnly(libs.jetbrainsAnnotations)
    annotationProcessor(libs.lombok)
}

tasks.withType<JavaCompile>().configureEach {
    options.isIncremental = true
    options.isFork = true
}

tasks {

    java {
        toolchain {
            languageVersion.set(JavaLanguageVersion.of(16))
        }
    }
    withType<JavaCompile> {
        options.encoding = "UTF-8"
    }
    build {
        dependsOn(shadowJar)
    }
    shadowJar {
        delete("${project.buildDir}/resources")
        delete("${project.buildDir}/libs")
        archiveFileName.set("${project.name}-${project.version}.jar")
        relocate("net.byteflux", "$relocate.byteflux")
        relocate("me.fixeddev.commandflow-bukkit", "$relocate.cmdFlow")
        relocate("me.fixeddev.commandflow-universal", "$relocate.cmdFlow")
        relocate("org.bstats", "$relocate.bStats")
        //relocate("team.unnamed", "$relocate.commonsError")
        relocate("com.github.simplix-softworks", "$relocate.leonhardStorage")
        relocate("org.jsoup", "$relocate.jSoup")
        minimize()
    }
    processResources {
        filesMatching("plugin.yml") {
            expand(
                "name" to rootProject.name,
                "version" to project.version,
                "group" to project.group,
                "author" to project.property("author"),
                "description" to project.property("description"),
            )
        }
    }

}

fun commitsSinceLastTag(): String {
    val tagDescription = ByteArrayOutputStream()
    exec {
        commandLine("git", "describe", "--tags")
        standardOutput = tagDescription
    }
    if (tagDescription.toString().indexOf('-') < 0) {
        return "0"
    }
    return tagDescription.toString().split('-')[1]
}

//var dependsDir = "${buildDir}/libs/dependencies/"

tasks.register<proguard.gradle.ProGuardTask>("proguard") {

    configuration("${buildDir}/proguard.pro")
    injars("${buildDir}/${project.name}-${project.version}.jar")
    outjars("${buildDir}/libs/${rootProject.name}_proguard.jar")

    //libraryjars("${System.getProperty("java.home")}/lib/rt.jar")
    //libraryjars(dependsDir)
}

ProGuard.pro (config)

Hi @Skjolberg ,

I can see some syntax errors in your configuration file, some comments are not starting with #, or some configuration rules that are partially commented out e.g.


#-keep public class proguard.gradle.* {
    public *;
#}

Normally ProGuard will error out on syntax issues, are you sure ProGuard is invoked? From your build.gradle file I can see a jar with suffix _proguard.jar should be created, is that the case?

Best regards,

Jonas