Can't keep annotations
Java class file shrinker, optimizer, obfuscator, and preverifier
Brought to you by:
guardsquare
Hello,
I'm trying to keep the annotations on the classes processed by Proguard. I am using this:
-keepattributes Annotation,EnclosingMethod,Signature,LineNumberTable,Exceptions,SourceFile,InnerClasses
and also this:
-keep @interface org.springframework.stereotype.Service
But the annotation is still removed from my classes.
Code to showcase the problem:
https://github.com/benji/proguard-keep-annotations
Any advice?
Thanks
The annotation is present in the bytecode, but the JVM can't resolve the annotation class at runtime. Adding spring-context-5.0.7.RELEASE.jar to the runtime classpath helps.
However, you're also suppressing all warnings. from ProGuard... There are many unresolved references. In the ProGuard task, you still need to specify the library jars on which the application builds, so ProGuard can resolve the references to essential classes like java.lang.Object and org.springframework.stereotype.Service.
You can also specify them as
-injars, if they should be included in the output. Cfr. the documentation (Troubleshooting > Warning: can't find referenced class) and the examples.For future reference adding the spring jars in the runtime classpath was enough to solve the issue. The getDeclaredAnnotations found the annotations successfully.
Thanks Eric for taking the time to help with this.