gradle-intellij-plugin didn't pack the jar generated by proguard in the zip file.

Answered

Hi, I'm using a build.gradle.kts like https://github.com/beansoft/intellij-platform-plugin-template-proguard/blob/main/build.gradle.kts
proguard is triggered before prepareSandbox then copy back and overwrite the jar file "build/libs/${rootProject.name}-${properties("pluginVersion")}.jar"
and it runs without error. But after the buildPlugin had finished successfully. I unzipped the packaged plugin, there is a file named "instrumented-${rootProject.name}-${properties("pluginVersion")}.jar" and it has not been obfuscated.
Why is that happened? And How to solve it?
Thank you very much for any help!!

0
2 comments

You're not supposed to obfuscate the base Jar file but the instrumented one instead. Please rely on the output of the instrumentedJar task instead of jar.

0

Jakub Chrzanowski This is my proguard task:
 

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

    configuration("proguard-rules.pro")

    injars(tasks.named("instrumentedJar")) // injars(tasks.named("jar"))

    outjars("build/${rootProject.name}-obfuscated.jar")

    val javaHome = System.getProperty("java.home")

    print("javaHome=$javaHome")
    if (properties("skipProguard").isPresent.not()) {
        File("$javaHome/jmods/")
            .listFiles()!!
            .forEach {
                libraryjars(it.absolutePath)
            }
    }

    libraryjars(configurations.compileClasspath.get())

    dontshrink()
    dontoptimize()
    adaptclassstrings("**.xml")
    adaptresourcefilecontents("**.xml") // or   adaptresourcefilecontents()
    overloadaggressively()
    printmapping("build/proguard-mapping.txt")

    target(JavaVersion.VERSION_17.toString())

    adaptresourcefilenames()
    optimizationpasses(9)
    allowaccessmodification()
    mergeinterfacesaggressively()
    renamesourcefileattribute("SourceFile")
    keepattributes("Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,*Annotation*,EnclosingMethod")
}

And the prepareSandbox:

prepareSandbox {
        if (properties("skipProguard").isPresent.not()) {
            dependsOn("proguard")
            doFirst {
                val original = File("build/libs/${rootProject.name}-${properties("pluginVersion")}.jar")
                println(original.absolutePath)
                val obfuscated = File("build/${rootProject.name}-obfuscated.jar")
                println(obfuscated.absolutePath)
                if (original.exists() && obfuscated.exists()) {
                    original.delete()
                    obfuscated.renameTo(original)
                    println("plugin file obfuscated")
                } else {
                    println("error: some file does not exist, plugin file not obfuscated")
                }
            }
        }
    }

But still, the chosen jar in the ZIP file is the normal one!

 

0

Please sign in to leave a comment.