Menu

#717 Can't keep annotations

v5.3.3
closed-invalid
annotations (3)
Medium
2018-07-30
2018-07-26
No

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

Discussion

  • Eric Lafortune

    Eric Lafortune - 2018-07-28

    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.

    -libraryjars <java.home>/jmods/java.base.jmod(!**.jar;!module-info.class)
    -libraryjars spring-context-5.0.7.RELEASE.jar
    ...
    

    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.

     
  • Eric Lafortune

    Eric Lafortune - 2018-07-28
    • status: open --> closed-invalid
    • assigned_to: Eric Lafortune
     
  • Benjamin Jaton

    Benjamin Jaton - 2018-07-30

    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.

     

Log in to post a comment.

MongoDB Logo MongoDB