Guice annotatedWith() binding doesn't work when using a Kotlin annotation


#1

Hello,
I have a strange problem. I am trying to follow an example at https://github.com/google/guice/wiki/BindingAnnotations - more specifically the @PayPal equivalent (not the @Named one).

So the binding in Kotlin looks like this:
bind(CreditCardProcessor::class.java).annotatedWith(PayPal::class.java).to(PayPalCreditCardProcessor::class.java)

The problem I’m facing is that if the @PayPal annotation comes from Java, it works just fine. But I’m not able to make it work with a PayPal annotation created in Kotlin.
Do you have any thoughts about what’s wrong and how to make the Kotlin annotations work with guice .annotatedWith() API?
Thanks.


#2

If you want to use annotation processing in Kotlin you will have to enable kapt (there is a plugin for that in gradle) and make sure to make your processor a dependency of the kapt configuration.