4

IntelliJ IDEA lets you add external annotations.

enter image description here

However, the files go straight into the project's root directory.

enter image description here

How do I change the folder?
I can't find a setting.

LppEdd
  • 20,274
  • 11
  • 84
  • 139

2 Answers2

3

This behavior is extremely confusing, and took me a long IDEA debug session to understand.
Let's say we start with a clean situation, and we add an external Annotation to a method of a library.

enter image description here

A popup appears, letting us choose the external Annotations root directory.

enter image description here

And we choose untitled3, the project's root directory. But ops, we made a mistake!
Now how can we change this directory? Where is it stored?
Well, actually not under any $projectRoot$/.idea/* XML file...

Let's debug IDEA. The "call" hierarchy is:

> AnnotateIntentionAction
  > AddAnnotationPsiFix#invoke
    > ExternalAnnotationsManagerImpl#annotateExternally

The last method annotateExternally calls AnnotationOrderRootType.getFiles(entry), where entry is a LibraryOrderEntry.

enter image description here

Here orderEntry.getRootFiles(getInstance()) gets called and the resulting VirtualFile(s) are used as library's external Annotations roots.

Where are they stored?

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

enter image description here

Now press CANC over the Annotations entry, and you're done... Finally.
You can restart over.

LppEdd
  • 20,274
  • 11
  • 84
  • 139
0

You may drag'n'drop the annotations.xml file in the Project pane and move it to the desired location or change the path explicitly in Project Structure | Project Settings | Modules -> module Paths | External Annotations

Olga Klisho
  • 1,206
  • 5
  • 7
  • No problem hahaha. Maybe can you guys add some info for libraries on the External Annotations help page? I doubt I'm alone in this. – LppEdd Mar 24 '20 at 18:19
  • Hmm I've tried to reproduce the same annotations positioning with sample gradle project and haven't managed to reproduce the case without explicit adding of gradle lib + annotations.xml path. Can you please describe how have you defined the following path location? – Olga Klisho Mar 24 '20 at 21:09
  • https://drive.google.com/open?id=1hw4fXvl3hQkosjVs39TFXzHvpZWrnOsa It's pretty simple. I defined two folders (`annotation-root-one`/`annotation-root-two`) as External Annotations paths in Project settings. Now, the first time you will add an external annotation to the `JSONObject#optJSONObject` method it will ask you where to put it, choose the root `untitled3`. That position will now be under the library settings as I showed in the answer (last image). The External Annotations paths are not used for libraries, only for local sources. But maybe I misunderstood and you meant something else? – LppEdd Mar 24 '20 at 22:48
  • Thanks for the sample and clarification. I got what you mean now, the case of annotating the external library will be added to the documentation. – Olga Klisho Mar 25 '20 at 12:17