Any trick to getting @MagicConstant work in libraries?

Answered

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?

1
4 comments

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 https://mvnrepository.com/artifact/org.jetbrains/annotations/17.0.0 or our own variant https://mvnrepository.com/artifact/org.realityforge.org.jetbrains.annotations/org.jetbrains.annotations/1.1.0 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 https://github.com/arez/arez/blob/master/core/src/main/java/arez/ArezContext.java#L394 and the annotation works fine within the project. However as soon we publish the libraries to Maven central as in https://mvnrepository.com/artifact/org.realityforge.arez/arez-core/0.150 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.

0

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.

0

Great - thanks for the heads up!

0

Please sign in to leave a comment.