Any trick to getting @MagicConstant work in libraries?


So we use @MagicConstant within an application to help us use constants correctly and it works great as long as the source is defined in the IDEA project. However, we would like to package these annotations as part of a library so downstream projects can make use of the same metadata. We have tried annotating the source and shipping both a sources jar and a normal jar or merging source into normal jar. We have also tried using external annotations. None of our downstream applications will use @MagicConstant for code completion or validation.

Is there anything I am missing or is this just not a supported scenario?


I guess I was not clear with my question ;)


We use the annotation fine and reference it via either the artifact that jetbrains publishes or our own variant of the source code ala or our own variant which just strips out a class and adds a descriptor for compatibility with GWT and/or google/j2cl.


However, we have created several libraries where we use the annotation like at and the annotation works fine within the project. However as soon we publish the libraries to Maven central as in and use the libraries in downstream projects, the @MagicConstant annotation is ignored.


I wonder if there is some additional action that is required to get IDEA to pick up these annotations or if it is a bug in IDEA. I could have sworn we have had this workin in the past but the current version (2019.2.3) does not seem to support this.


From what I can see, you've hit a problem which I filed as IDEA-225113. We fixed it and will backport to 2019.3.


Great - thanks for the heads up!


Please sign in to leave a comment.