21

I have created a plugin for IntelliJ Idea. In the plugin I have defined an annotation I want to use in my projects, but it doesn't seem to be accessible. How should I specify in the plugin.xml file the packages I want to expose?

John Bollinger
  • 121,924
  • 8
  • 64
  • 118
lowcoupling
  • 1,961
  • 5
  • 30
  • 52

2 Answers2

5

When you install a plugin, it will be on a certain place - e.g. C:\Users\xxx\.IdeaIC14\config\plugins\...

Now that you know where your jar file is, you can add it as a dependency to your project. If you use Maven, you can add something like this to your pom:

<dependency>
    <groupId>yourplugin</groupId>
    <artifactId>yourplugin</artifactId>
    <version>1</version>
    <systemPath>C:\Users\xxx\.IdeaIC14\config\plugins\yourplugin.jar</systemPath>
    <scope>system</scope>
</dependency>

Or you can install the jar into your local repository and then use it as normal maven dependency.

If not, then add the dependency directly in the project settings as it was any other jar.

plugin.xml has nothing to do with any of this, this is all about jars and classpath. What you could do in your plugin is some user friendly inspections and actions, which would add the dependency for you.

Meo
  • 10,698
  • 5
  • 41
  • 50
0

By default, plugins can automatically read and access public members of any other plugin installed on the same IDE (ie. your plugin can read public variables, call public functions - everything goes on the same classpath). If you depend on another plugin, you must first add it as an explicit dependency within the plugin configuration file, so that the end user's IDE will know to download and install your plugin's required plugin dependencies if they are missing.

During development, you should now be using Gradle. In your project's build.gradle (or build.gradle.kts) file, the intellij.plugins property of the gradle-intellij-plugin will let you specify the the id and version of the plugin dependency. The values for these attributes can be found on the Plugin Repository, cf. Plugin XML ID). Subsequently, the gradle-intellij-plugin will add the desired IntelliJ Platform Plugin to your project as an External Library, thereby allowing you to get code completion, static analysis and test your plugin alongside its dependencies inside the plugin sandbox (via ./gradlew runIde).

Plugins should avoid using other plugins' internal classes for stability reasons. If you wish to enable other plugins to use your plugin programmatically (ie. suppose you want to provide an API), then the IntelliJ Platform has the concept of so-called, Extension Points. These will allow you to define a concrete interface, or contract for other plugins to access the functionality of your plugin, without needing to know much about its source code. Using extension points has the added benefit of decoupling those plugins from any internal plugin refactoring.

breandan
  • 1,581
  • 19
  • 38