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?
-
1Maybe you should create a project with this classes, interfaces and annotation, on which your main project will depend? – Dmitry Ginzburg May 06 '15 at 10:20
-
These annotations are used by the plugin thus i want them to be part of the plugin. i don't want the user to redefine them. I would Luke to import them from the plugin, i guess it is possible – lowcoupling May 06 '15 at 10:23
-
1Disagree with the close vote. Question is perfectly clear - please leave open. – vikingsteve May 06 '15 at 11:21
-
Are you able to get other similar plugins that you' didn't create to work in this way? – Carlos Bribiescas May 06 '15 at 12:57
-
1Why do you want to do it this way, instead of shipping your classes in a jar that can be easily taken in as a maven `
`? – vikingsteve May 08 '15 at 08:08 -
I have tried to do that but i don't know how to refer to a jar contained in a plugin – lowcoupling May 08 '15 at 12:23
2 Answers
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.
- 10,698
- 5
- 41
- 50
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.
- 1,581
- 19
- 38