Proguard: Keep annotation of specific method

2019-07-06 15:53发布

问题:

Have have this class in my Minecraft Bukkit plugin:

public class AsyncPlayerChatListener implements Listener
{
    @EventHandler(priority = EventPriority.HIGH)
    public void onEvent(AsyncPlayerChatEvent event)
    {
    }
}

And I want to keep the method along with its annotation. This is my current proguard configuration:

-keep class * extends org.bukkit.event.Listener {
    @org.bukkit.event.EventHandler <methods>;
}

ProGuard currently keeps the method and removes the annotation. How can I specify to keep all EventHandler annotations in classes implementing Listener (or all EventHandler annotation anywhere, would be fine too)?

I know

-keepattributes *Annotation*

exists, but I guess this would make ProGuard keep any annotation anywhere.

回答1:

I was unforunately unable to test this, but this may help(?):

-keepclassmembers class * extends org.bukkit.event.Listener {
    @org.bukkit.event.EventHandler public *;
}