8.9 KiB
A plugin may depend on classes from other plugins, either bundled, third-party, or by the same author. This document describes the syntax for declaring plugin dependencies and optional plugin dependencies. For more information about dependencies on the IntelliJ Platform modules, see Part II of this document: .
For adding dependencies on 3rd party libraries, use regular Gradle dependency management.
{type="note"}
To express a dependency on classes from other plugins or modules, perform the following three required steps detailed below on this page:
- Locate Plugin ID
- Project Setup
- Declaration in plugin.xml
If java.lang.NoClassDefFoundError
occurs at runtime, it means that either Step 3 was omitted or loading the plugin dependency failed (please check log files from Development Instance).
1. Locating Plugin ID and Preparing Sandbox
A compatible version must be chosen carefully according to the plugin's compatibility. It is not possible to specify the minimum/maximum version for the dependent plugin. (Issue)
JetBrains Marketplace
For plugins published on JetBrains Marketplace:
- Open plugin's detail page
- Select Versions tab
- Open detail page for the desired version, displaying the Compatibility Range and Plugin ID
Bundled and Other Plugins
When using Gradle IntelliJ Plugin, all bundled plugins can be listed using listBundledPlugins
task.
When using DevKit and for non-public plugins, locate the plugin's main JAR file containing META-INF/plugin.xml descriptor with <id>
tag (or <name>
if not specified).
Bundled plugins are located in $PRODUCT_ROOT$/plugins/$PLUGIN_NAME$/lib/PLUGIN_NAME
.jar.
IDs of Bundled Plugins
The following table lists some commonly used bundled plugins and their ID. See also and .
Preparing Sandbox
If the plugin is not bundled with the target IDE, run the (sandbox) IDE Development Instance of your target IDE and install the plugin there.
2. Project Setup
Depending on the chosen development workflow (Gradle or DevKit), one of the two following steps is necessary.
Please see the
intellij.plugins
property for acceptable values.
{type="note"}
Add the dependency to the intellij.plugins
parameter in your build script:
intellij {
plugins.set(listOf("com.example.another-plugin:1.0"))
}
intellij {
plugins = ['com.example.another-plugin:1.0']
}
Transitive dependencies required for tests must currently be specified explicitly.
{type="note"}
Existing DevKit-based projects can be converted to use Gradle setup where dependency management is fully automated.
{type="note"}
Add the JARs of the plugin on which the project depends to the Classpath of the IntelliJ Platform SDK.
Do not add the plugin JARs as a library: this will fail at runtime because the IntelliJ Platform will load two separate copies of the dependency plugin classes.
{type="warning"}
To do that, open the Project Structure dialog, select the SDK used in the project, press the + button in the Classpath tab, and select the plugin JAR file(s):
- For bundled plugins, the plugin JAR files are located in plugins/$PLUGIN_NAME$ or plugins/$PLUGIN_NAME$/lib under the main installation directory. If you're not sure which JAR to add, you can add all of them.
- For non-bundled plugins, the plugin JAR files are located in config/plugins/$PLUGIN_NAME$ or config/plugins/$PLUGIN_NAME$/lib under the directory specified as Sandbox Home in the IntelliJ Platform Plugin SDK settings.
3. Dependency Declaration in plugin.xml
Regardless of whether a plugin project uses , or , the correct module must be listed as a dependency in plugin.xml.
If a project depends on another plugin, the dependency must be declared like a module.
If only general IntelliJ Platform features (APIs) are used, then a default dependency on com.intellij.modules.platform
must be declared.
To display a list of available IntelliJ Platform modules, invoke the code completion feature for the <depends>
element contents while editing the plugin project's plugin.xml file.
In the plugin.xml, add a <depends>
tag with the dependency plugin's ID as its content.
Continuing with the example from Project Setup above, the dependency declaration in plugin.xml would be:
<depends>com.example.another-plugin</depends>
Optional Plugin Dependencies
A plugin can also specify an optional plugin dependency. In this case, the plugin will load even if the plugin it depends on is not installed or enabled, but part of the plugin's functionality will not be available.
Declare additional optional="true"
and config-file
attribute pointing to optional plugin descriptor file:
<depends
optional="true"
config-file="myPluginId-optionalPluginName.xml">dependency.plugin.id</depends>
Additional plugin descriptor files must follow the naming pattern myPluginId-
NAME
.xml resulting in unique filenames to prevent problems with classloaders in tests (Details).
{type="note"}
For example, if a plugin adds additional highlighting for Java and Kotlin files, use the following setup.
The main plugin.xml will define an annotator for Java and specify an optional dependency on the Kotlin plugin (plugin ID org.jetbrains.kotlin
):
plugin.xml
<idea-plugin>
...
<depends
optional="true"
config-file="myPluginId-withKotlin.xml">org.jetbrains.kotlin</depends>
<extensions defaultExtensionNs="com.intellij">
<annotator
language="JAVA"
implementationClass="com.example.MyJavaAnnotator"/>
</extensions>
</idea-plugin>
Then create a file called myPluginId-withKotlin.xml, in the same directory as the main plugin.xml file. In that file, define an annotator for Kotlin:
myPluginId-withKotlin.xml
<idea-plugin>
<extensions defaultExtensionNs="com.intellij">
<annotator
language="kotlin"
implementationClass="com.example.MyKotlinAnnotator"/>
</extensions>
</idea-plugin>