proguard.conf option -keep and -dontwarn not work

60 Views Asked by At

I'm building a regular uber-jar (not native executable file) based on Quarkus. and I also wanna obfuscate the uber-jar. so I build the jar file with

 ./gradlew quarkusBuild -Dquarkus.package.type=uber-jar

and here is part of build.gradle.kts

 tasks.register("proguard", JavaExec::class) {
    classpath = files("$rootDir/proguard/lib/proguard.jar")
    main = "proguard.ProGuard"
    args(
        "-include",
        "proguard.conf",
        "-injars",
        "build/my-project-1.0.0-runner.jar",
        "-outjars",
        "build/app.jar"
    )
 }

howerver, after I build the jar and run ./gradlew proguard, I got tons of warnings,

Warning: there were 3260 unresolved references to classes or interfaces.

Warning: there were 56 unresolved references to program class members.

Warning: there were 204 unresolved references to library class members.

Thounds of warnings !! I think maybe I should use option -keep to prevent some package from obfuscating.but there are too many warnings and I wonder is it the right way to fix the warning. anyway I add some -keep option in proguard.conf, and it is interesting that I find some option not work. here is my proguard.conf:

-target 17
# -verbose

-dontshrink

-dontoptimize

-dontwarn

-adaptclassstrings

-libraryjars /usr/lib/jvm/temurin-17-jdk-amd64/jmods/java.base.jmod
-libraryjars /usr/lib/jvm/temurin-17-jdk-amd64/jmods/java.logging.jmod
-libraryjars /usr/lib/jvm/temurin-17-jdk-amd64/jmods/java.sql.jmod
-libraryjars /usr/lib/jvm/temurin-17-jdk-amd64/jmods/java.xml.jmod




# Keep all Quarkus-related classes and resources
-keep class io.quarkus.** { *; }
-keep class io.quarkus.vertx.** { *; }
-keep interface io.quarkus.vertx.** { *; }
-keep class io.vertx.** { *; }
-keep class io.vertx.**
-keep class io.vertx.** {
    *;
}

-keep interface io.vertx.** { *; }
-keep interface com.sun.** { *; }
-keep interface io.quarkus.** { *; }
-keep class javax.** { *; }
-keep class com.google.common.** { *; }
-keep class com.sun.** { *; }
-keep class java.util.logging.Level { *; }
-keep class com.fasterxml.jackson.annotation.** { *; }
-dontwarn  com.fasterxml.jackson.databind
-dontwarn  javax.annotation.**
-dontwarn  javax.xml.**
-dontwarn  javax.**
-dontwarn  java.awt.**
-keep class javax.annotation.** { *; }
-keep class  org.apache.log4j.** { *; }
-keep class  org.apache.log4j.**
-keep class  org.jboss.** { *; }
-keep class  org.jboss.**
-keep class  io.netty.** { *; }
-keep class  io.netty.**
-keep class  sun.misc.** { *; }
-keep class  sun.misc.**

-keepattributes *Annotation*,Signature

# Keep application-specific classes and resources
-keep class org.myproject.** { *; }

As you can see , I've add -keep class io.netty.** { *; } -keep class io.netty.** but still got io.netty warning:

// part of the massive warning

Warning: io.netty.handler.ssl.OpenSsl: can't find referenced class io.netty.internal.tcnative.SSL
Warning: io.netty.handler.ssl.OpenSsl: can't find referenced class io.netty.internal.tcnative.SSLContext

// ...
// also, I've add -keep org.jboss.**
Warning: io.netty.handler.codec.marshalling.LimitingByteInput: can't find referenced class org.jboss.marshalling.ByteInput 

// and some similar occasion, I've add the keep option but still get warning
Warning: com.google.common.util.concurrent.AbstractFuture$UnsafeAtomicHelper: can't find referenced class sun.misc.Unsafe


// I've add java.base.jmod and java.logging.jmod, java.sql.jmod and java.xml.jmod 
// now I have to add java.beans.jmod ? I have to add all the jmod in the jdk?
Warning: com.fasterxml.jackson.databind.ext.Java7SupportImpl: can't find referenced class java.beans.Transient
Warning: com.fasterxml.jackson.databind.ext.Java7SupportImpl: can't find referenced class java.beans.ConstructorProperties
Warning: com.fasterxml.jackson.databind.ext.Java7SupportImpl: can't find referenced class java.beans.Transient



maybe you've notice that I have even add -dontwarn but why I still got the thounds warnings .

0

There are 0 best solutions below