Provide custom annotations in plugin

Answered

Hi,

I initially posted this as a follow up on this thread https://intellij-support.jetbrains.com/hc/en-us/community/posts/360003921880-Provide-custom-java-annotations-with-plugin-?page=1#community_comment_360002650520, but not sure if anyone will be notified of the new questions there so I am posting it now as a new thread. My appologies if it was enough to just ask there.

I have a plugin that makes use of some annotations defined by me which are to be used by clients of the plugin to annotate some code. Here are the steps I did:

  • I extracted the annotations into a separate project and uploaded the resulting har in Maven Central.
  • I added as an implementation dependency in the plugin project the annotations. This results in everything compiling but the resulting jar for the plugin does not contain any annotation classes.
  • I implemented ExternalLibraryResolver to have a quickfix for the annotations dependency
  • I then openend a separate test project where I installed the plugin and also I added in my build.gradle as a implementation dependency the annotations required by the plugin.
  • Yet when the plugin runs it throws a NoClassDefFound error for the annotations.

My question is: shouldnt the annotations be available at runtime to the plugin via the dependencies declared in the test project I created?

If not then what should the approach be here? Make sure to pack the annotation dependencies inside the plugin jar? Any advice on the easiest way to do that?

0
2 comments

com.intellij.codeInsight.daemon.quickFix.ExternalLibraryResolver job is to provide "automatic" mapping to relevant dependency coordinates for the current open project inside the IDE. The classpath of the current project has nothing to do with whatever classpath the plugin running inside the IDE has. If your plugin's code needs the same annotations at runtime for its code, the library must be packaged inside the plugin distribution.

0

Thanks for the answer Yann. I found out I made a mistake. I did not read the docs well enough so I thought the output of the buildPlugin Gradle task will be in the libs folder. I found out it is in the distribution folder and once I used that artifact everything seemed to work.

0

Please sign in to leave a comment.