What is the preferred solution for distributing external annotations?

已回答

I am a library author and I publish my library to jcenter. I used external annotations to add annotations to my library, but I couldn't find a satisfactory solution to distribute these annotations.

I have tried to package the annotations into an artifact with the annotations classifier, and I have also tried to package annotations.xml into the source code jar package, but IDEA does not automatically recognize these annotations for both.

Is there any suitable way for users of my library to easily see these annotations?

0

Hi. It is possible to store external annotations as maven artifact, please check: https://www.jetbrains.com/help/idea/external-annotations.html#external-annotations-maven

-1
Avatar
Permanently deleted user

@Petr Rastegaev

I have tried publishing external annotations jar as artifact with the annotations classifier , but the effect is very bad:

This approach seems to work only for projects managed directly by IDEA. For projects managed with Gradle (Probably the same for maven projects, but I didn't try it), IDEA will neither automatically download external annotations jar, nor provide corresponding options in the project structure menu, and even manually add external annotations jar to Gradle's dependencies, IDEA will still not recognize these annotations.

If there is no better solution, this feature is really too bad for publishing maven libraries. I hope IDEA can at least understand the annotations.xml in the source jar in the future.

0

Glavo,

At the moment, the lookup for external annotations artifact is limited to a list of known libraries. Looking for annotations for all dependencies of a Maven/Gradle-based project is too time-consuming. The list is currently hardcoded but can be customized for an IDEA installation.
Using annoations.xml from sources jar makes things complicated if an updated version of annotations should be published for already published binaries. Still, this is an interesting approach, so could you please add it as a comment to https://youtrack.jetbrains.com/issue/IDEA-201991

0
Avatar
Permanently deleted user

@... What do you mean by "can be customized for an IDEA installation"? I checked the source code that resolves a file named `predefinedExternalAnnotations.json`, however I could not find how to provide my own. The comment athttps://youtrack.jetbrains.com/issue/IDEA-200003#focus=streamItem-27-3682204.0-0 said to change the file at <idea_home>/config/com.intellij/predefinedExternalAnnotations.json but not only does that file not exist, it seems the directory structure has been changed in recent versions and there's no config directory anymore...

0

@... thank you for your patience.

Indeed, the `predefinedExternalAnnotations` file is not created in 2020.1 or 2020.2EAP and this is a straght bug: https://youtrack.jetbrains.com/issue/IDEA-243907

0
Avatar
Permanently deleted user

Nikita Skvortsov What's the current way to access that configuration? I looked through the contents of ~/Library/Application Support/JetBrains and I don't see predefinedExternalAnnotations.json, or even a relevant folder config:

07:42:31 ~/Library/Application Support/JetBrains  $ find . -name 'config'
./IntelliJIdea2021.1/plugins/sonarlint-intellij/omnisharp/osx/etc/config
./IntelliJIdea2021.1/plugins/sonarlint-intellij/omnisharp/linux/etc/config

The ticket you link says that the functionality has been moved into a separate plugin. Which plugin is that?

0

@... It's  ~/Library/Application Support/JetBrains/IntelliJIdea2021.3/extensions/com.intellij.java/predefinedExternalAnnotations.json

0
Avatar
Permanently deleted user

Konstantin Annikov Thanks for the quick reply. I see IntelliJIdea2021.3/extensions/com.intellij.database/ and IntelliJIdea2021.3/extensions/com.intellij.javaee.jpa, but not com.intellij.java.

I see there is an ​external​Annotation extension listed here, but it seems one needs to write a plugin in order to use it. (Not very familiar with the subject, had to google difference between extensions and plugins)

0

This file is being created during project syncing with Maven/Gradle. See file creation  and usages of getLocations: Maven and Gradle

0

请先登录再写评论。