Proguard for logback

Hi,

i am very new to proguard and have question about this.

I create a simple hello world using logback:

public class App {
// final static Logger logger = LoggerFactory.getLogger(App.class);
public static void main(String[] args) {
notMain();
}

public static void notMain() {
    Logger logger = LoggerFactory.getLogger(App.class);
    logger.info("Hello Worlddddd");
    System.out.println("abc");
}

}

i use maven for these library:

<dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-classic</artifactId>
    <version>1.5.6</version>
</depe> ndency>
ch.qos.logback logback-core 1.5.6

and my logback config is like this:

-injars TestLogging-1.0-SNAPSHOT-jar-with-dependencies.jar
-outjars TestLogging_out.jar

-libraryjars Java/jdk23/jmods/java.base.jmod(!**.jar;!module-info.class)
-libraryjars Java/TestLogging/target/dependency/logback-classic-1.5.6.jar
-libraryjars Java/TestLogging/target/dependency/logback-core-1.5.6.jar
-libraryjars Java/TestLogging/target/dependency/slf4j-api-2.0.13.jar

-printmapping out.map
-renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable

-keepclassmembers class org.slf4j.** { ; }
-keepclassmembers class ch.
* { *; }

-keep public class logging.test.App {
public static void main(java.lang.String[]);
}

-keepattributes Exceptions,InnerClasses,Signature,Deprecated,
SourceFile,LineNumberTable,Annotation,EnclosingMethod

-dontwarn jakarta.**
-dontwarn org.xml.sax.**
-dontwarn java.util.logging.**
-dontwarn javax.naming.**
-dontwarn javax.xml.stream.**
-dontwarn javax.xml.parsers.**
-dontwarn org.codehaus.**
-dontwarn javax.xml.namespace.**

when i run with the original jar, and with the proguard jar, the result is different. the proguard jar seems to disable the logger service provider. i tried to google how to solve (also read the document) but still unable to find the solution. any help very much appreciated. and please let me know if more detail is needed

I found the solution. by using -dontoptimize and it works fine. thanks!

1 Like