Hi, I am trying to make custom annotation for Guic...
# announcements
d
Hi, I am trying to make custom annotation for Guice in kotlin codebase, it currenly doesn't recognize kotlin annotations it seems. There was a suggestion to use kapt to make it work, but I am not sure what exactly should I do with it
đź’Ż 1
c
Guice is a runtime DI library, kapt is for compile-time annotation processing. Do you have the annotation retention set to runtime?
Copy code
@Retention(AnnotationRetention.RUNTIME)
annotation class CustomGuiceAnnotation
d
ah, I do have that set yeah
I use that annotation in primary constractor field and
@Target
is set to
FIELD
I also tried using something like
@field:CustomGuiceAnnotation
at the injection side to no avail
c
The
@Retention
should go on the annotation class itself, right next to
@Target
, not on the constructor or a field
d
yeah I know
that’s what I did
I just wanted to tell you where I am using the annotation
c
Ah, got it. I am inclined to say that the annotation itself is not the issue, and that your setup with Guice is the problem. Does the same annotation work as expected if it’s in Java?
d
I didn’t try to use in in Java, our codebase is fully kotlin
@Named
annotation works with similar setup
so I thought the problem was about custom annotation
so you think Guice should work fine with Kotlin annotations?
c
Yeah, there should be no difference between Java and Kotlin annotations, Guice doesn’t know the difference between the two.