External Annotations Third Party Library Path

In my project I have now created several annotation files for third party libraries including Guava, Dagger, slf4j and netty.  I have put the annotations in an annotations folder at the root of source control.  How can I tell IntelliJ that <project root>/annotations contains third party library annotations and it should always look there (in the appropriate package folder) for third party library annotations?  Currently, the only way I know how to deal with this is to try to add an annotation to one of the libraries and then point it at the annotations folder when it prompts.  That annotation will then be merged with the existing ones and the entry for annotations will be added to the library.

The problem here is that the IntelliJ project files are not committed to source control, instead they are generated from gradle (./gradlew idea) or from IntelliJ auto-import of build.gradle.  This means that anytime someone new clones the repository (or I do a git clean -dfx on my existing clone) I lose the mapping of libraries to their annotations folder.

Ideally, there is something I can add to my gradle file such that when the IntelliJ project is created the annotations are automatically mapped.  In lieu of that I would like to only have to do one operation to link up all of the annotations rather than having to go through and manually fix teh annotations for every dependency I have (which can get large for a large project).

1 comment

AFAIK "gradlew idea" task doesn't manage external annotations. It probably should, but it'd be better if Gradle team decided on the correct way of handling it, added this support to the scripts and then IDEA's import could honor that setting.

As a workaround, you can add to your Gradle script some executable code that patches the needed iml/xml files and adds the necessary tags with external annotation roots there explicitly. It can be done via Groovy's XML handling support or using some utility to apply a precomputed patch (assuming that the regenerated IDEA project files are similar enough to the previous ones).


Please sign in to leave a comment.