I was looking for the same, but after considering the documentation at great length, and related questions on Stack Overflow, my conclusion is this is not supported.
At the time of writing, only the following options related to annotations can be passed to -keepattributes
. For runtime visible annotations:
RuntimeVisibleAnnotations
: keep all annotations on classes, fields, and methods
RuntimeVisibleParameterAnnotations
: keep all annotations on method parameters
RuntimeVisibleTypeAnnotations
: keep all annotations on generic types, instructions, etc. (not certain what ".etc" is supposed to mean here)
Matching selections for runtime invisible annotations are: RuntimeInvisibleAnnotations
, RuntimeInvisibleParameterAnnotations
, and RuntimeInvisibleTypeAnnotations
. I couldn't find any use case for retaining these.
Lastly AnnotationDefault
retains annotation default values.
In my opinion, the wildcard options for -keepattributes
(?
and *
) do more harm than good. They are easily misinterpreted (like I originally did, and others do, and you seem to desire) as a way to specify specific annotations, but this is not the case.
The common -keepattributes *Annotation*
option simply selects all of the options listed above.