更改 IDEA 2019.3+ 中的外部注释位置

Change external annotations location in IDEA 2019.3+

IntelliJ IDEA 允许您添加外部注释。

但是,文件会直接进入项目的根目录。

如何更改文件夹?
我找不到设置。

您可以将 annotations.xml 文件拖放到 项目窗格 中并将其移动到所需位置或在 项目结构中显式更改路径 |项目设置 |模块 -> 模块路径 |外部注释

这种行为非常令人困惑,我花了很长时间才了解 IDEA 调试会话。
假设我们从一个干净的情况开始,我们将一个外部注释添加到 library.

的方法中

出现一个弹出窗口,让我们选择外部注释根目录。

然后我们选择untitled3,项目的根目录。但是啊,我们错了!
现在我们如何更改此目录?它存储在哪里?
嗯,其实不在任何 $projectRoot$/.idea/* XML 文件下...

让我们调试IDEA。 "call" 层次结构是:

> AnnotateIntentionAction
  > AddAnnotationPsiFix#invoke
    > ExternalAnnotationsManagerImpl#annotateExternally

最后一个方法 annotateExternally 调用 AnnotationOrderRootType.getFiles(entry),其中 entryLibraryOrderEntry.

此处 orderEntry.getRootFiles(getInstance()) 被调用,结果 VirtualFile(s) 用作库的外部注释根。

它们存放在哪里?

> Project structure
  > Modules
    > *your main module with dependencies*
      > *your library*
        > DOUBLE LEFT CLICK

现在在 Annotations 条目上按 CANC,您就大功告成了……最后。
你可以重新开始。