Configuring Gradle for IntelliJ Platform Plugins
This page serves as a guide to Gradle-based plugin configuration for IntelliJ Platform projects. The IntelliJ IDEA Ultimate and Community editions bundle the Gradle and Plugin DevKit plugins to support Gradle-based development. The Getting Started with Gradle page provides a tutorial for creating Gradle-based IntelliJ Platform plugins. It may be useful to review the IntelliJ Platform page, particularly the description of versioning in the Open Source section.
- Overview of the IntelliJ IDEA Gradle Plugin
- Guide to Configuring Gradle Plugin Functionality
- Configuring the Gradle Plugin for Building IntelliJ Platform Plugin Projects
- Configuring the Gradle Plugin for Running IntelliJ Platform Plugin Projects
- Managing Directories used by the Gradle Plugin
- Controlling Downloads by the Gradle Plugin
- Patching the Plugin Configuration File
- Publishing with the Gradle Plugin
- Common Gradle Plugin Configurations for Development
Overview of the IntelliJ IDEA Gradle Plugin
The IntelliJ IDEA Gradle plugin is built from the open-source project gradle-intellij-plugin
.
The plugin adds Gradle tasks for the build.gradle
file that enable developing IntelliJ Platform plugins.
The README file for the gradle-intellij-plugin
project is the reference for configuring these tasks.
When getting started, there are several items to note on the README page:
- At the top of the page, the latest production version of the IntelliJ IDEA Gradle plugin is listed.
- Also at the top is the minimum version of Gradle required to support the IntelliJ IDEA Gradle plugin.
- The table of extended Gradle Tasks has a succinct description for each task added by the plugin.
This documentation will focus on the configuration and use four of those tasks:
- Setup DSL -
intellij { ... }
. - Running DSL -
runIde { ... }
- Patching DSL -
patchPluginXml { ... }
- Publishing DSL -
publishPlugin { ... }
- Setup DSL -
- Examples are always a helpful resource, and at the bottom of the page are links to example open source IntelliJ Platform plugin projects based on Gradle.
- Almost every Gradle plugin attribute has a default value that will work to get started on a Gradle-based IntelliJ Platform plugin project.
Guide to Configuring Gradle Plugin Functionality
This section presents a guided tour of Gradle plugin attributes to achieve commonly desired functionality.
Configuring the Gradle Plugin for Building IntelliJ Platform Plugin Projects
By default, the Gradle plugin will build a plugin project against the IntelliJ Platform defined by the latest EAP snapshot of the IntelliJ IDEA Community Edition.
If a matching version of the specified IntelliJ Platform is not available on the local machine, the Gradle plugin downloads the correct version and type. IntelliJ IDEA then indexes the build and any associated source code and JetBrains Java Runtime.
IntelliJ Platform Configuration
Explicitly setting the Setup DSL attributes intellij.version
and intellij.type
tells the Gradle plugin to use that configuration of the IntelliJ Platform to build the plugin project.
If a local installation of IntelliJ IDEA is the desired type and version of the IntelliJ Platform, use intellij.localPath
to point to that installation.
If the intellij.localPath
attribute is set, do not set the intellij.version
and intellij.type
attributes as this could result in undefined behavior.
Plugin Dependencies
IntelliJ Platform plugin projects may depend on either bundled or third-party plugins.
In that case, a project should build against a version of those plugins that match the IntelliJ Platform version used to build the plugin project.
The Gradle plugin will fetch any plugins in the list defined by intellij.plugins
.
See the Gradle plugin README for information about specifying the plugin and version.
Note that this attribute describes a dependency so the Gradle plugin can fetch the required artifacts.
The IntelliJ Platform plugin project is still required to declare these dependencies in its Plugin Configuration (plugin.xml
) file.
Configuring the Gradle Plugin for Running IntelliJ Platform Plugin Projects
By default, the Gradle plugin will use the same version of the IntelliJ Platform for the IDE Development Instance as was used for building the plugin. Using the corresponding JetBrains Runtime is also the default, so for this use case no further configuration is required.
Running Against Alternate Versions and Types of IntelliJ Platform-Based IDEs
The IntelliJ Platform IDE used for the Development Instance can be different from that used to build the plugin project.
Setting the Running DSL attribute runIde.ideDirectory
will define an IDE to be used for the Development Instance.
This attribute is commonly used when running or debugging a plugin in an alternate IntelliJ Platform-based IDE.
Running Against Alternate Versions of the JetBrains Runtime
Every version of the IntelliJ Platform has a corresponding version of the JetBrains Runtime.
A different version of the runtime can be used by specifying the runIde.jbrVersion
attribute, describing a version of the JetBrains Runtime that should be used by the IDE Development Instance.
The Gradle plugin will fetch the specified JetBrains Runtime as needed.
Managing Directories used by the Gradle Plugin
There are several attributes to control where the Gradle plugin places directories for downloads and for use by the IDE Development Instance.
The location of the sandbox home directory and its subdirectories can be controlled with Gradle plugin attributes.
The intellij.sandboxDirectory
attribute is used to set the path for the sandbox directory to be used while running the plugin in an IDE Development Instance.
Locations of the sandbox subdirectories can be controlled using the runIde.configDirectory
, runIde.pluginsDirectory
, and runIde.systemDirectory
attributes.
If the intellij.sandboxDirectory
path is explicitly set, the subdirectory attributes default to the new sandbox directory.
The storage location of downloaded IDE versions and components defaults to the Gradle cache directory.
However, it can be controlled by setting the intellij.ideaDependencyCachePath
attribute.
Controlling Downloads by the Gradle Plugin
As mentioned in the section about configuring the intellij platform used for building plugin projects, the Gradle plugin will fetch the version of the IntelliJ Platform specified by the default or by the intellij
attributes.
Standardizing the versions of the Gradle plugin and Gradle system across projects will minimize the time spent downloading versions.
There are controls for managing the IntelliJ IDEA Gradle plugin version, and the version of Gradle itself.
The Gradle plugin version is defined in the plugins {}
section of a project’s build.gradle
file.
The Gradle version is in defined in a project’s gradle-wrapper.properties
.
Patching the Plugin Configuration File
A plugin project’s plugin.xml
file has element values that are “patched” at build time from the attributes of the patchPluginXml
(Patching DSL) task.
As many as possible of the attributes in the Patching DSL will be substituted into the corresponding element values in a plugin project’s plugin.xml
file:
- If a
patchPluginXml
attribute default value is defined, the attribute value will be patched in plugin.xml regardless of whether thepatchPluginXml
task appears in thebuild.gradle
file.- For example, the default values for the attributes
patchPluginXml.sinceBuild
andpatchPluginXml.untilBuild
are defined based on the declared (or default) value ofintellij.version
. So by defaultpatchPluginXml.sinceBuild
andpatchPluginXml.untilBuild
are substituted into the<idea-version>
element’ssince-build
anduntil-build
attributes in theplugin.xml
file.
- For example, the default values for the attributes
- If a
patchPluginXml
attribute value is explicitly defined, the attribute value will be substituted inplugin.xml
.- If both
patchPluginXml.sinceBuild
andpatchPluginXml.untilBuild
attributes are explicitly set, both are substituted inplugin.xml
. - If one attribute is explicitly set (e.g.
patchPluginXml.sinceBuild
) and one is not (e.g.patchPluginXml.untilBuild
has default value,) both attributes are patched at their respective (explicit and default) values.
- If both
- For no substitution of the
<idea-version>
element’ssince-build
anduntil-build
attributes, one of the following must appear in thebuild.gradle
file:- Either set
intellij.updateSinceUntilBuild = false
, which will disable substituting bothsince-build
anduntil-build
attributes, - Or, for independent control, set
patchPluginXml.sinceBuild(null)
andpatchPluginXml.untilBuild(null)
depending on whether the intention is to disable one or both substitutions.
- Either set
A best practice to avoid confusion is to replace the elements in plugin.xml
that will be patched by the Gradle plugin with a comment.
That way the values for these parameters do not appear in two places in the source code.
The Gradle plugin will add the necessary elements as part of the patching process.
For those patchPluginXml
attributes that contain descriptions such as changeNotes
and pluginDescription
, a CDATA
block is not necessary when using HTML elements.
As discussed in Components of a Wizard-Generated Gradle IntelliJ Platform Plugin, the Gradle properties project.version
, project.group
, and rootProject.name
are all generated based on the input to the Wizard.
However, the IntelliJ IDEA Gradle plugin does not combine and substitute those Gradle properties for the default <id>
and <name>
elements in the plugin.xml
file.
The best practice is to keep project.version
current.
By default, if you modify project.version
in build.gradle
, the Gradle plugin will automatically update the <version>
value in the plugin.xml
file.
This practice keeps all version declarations synchronized.
Publishing with the Gradle Plugin
Please review the Publishing Plugins with Gradle page before using the Publishing DSL attributes. That documentation explains three different ways to use Gradle for plugin uploads without exposing account credentials.
Common Gradle Plugin Configurations for Development
Different combinations of Gradle plugin attributes are needed to create the desired build or IDE Development Instance environment. This section reviews some of the more common configurations.
Plugins Targeting IntelliJ IDEA
IntelliJ Platform plugins targeting IntelliJ IDEA have the most straightforward Gradle plugin configuration.
- Determine the version of IntelliJ IDEA to use for building the plugin project; this is the desired version of the IntelliJ Platform.
This can be EAP (default) or determined from the build number ranges.
- If a production version of IntelliJ IDEA is the desired target, set the
intellij
version attributes accordingly. - Set the necessary plugin dependencies, if any.
- If a production version of IntelliJ IDEA is the desired target, set the
- If the plugin project should be run or debugged in an IDE Development Instance based on the same IntelliJ IDEA version, no further attributes need to be set for the IDE Development Instance.
This is the default behavior and is the most common use case.
- If the plugin project should be run or debugged in an IDE Development Instance based on an alternate version of the IntelliJ Platform, set the Running DSL attribute accordingly.
- If the plugin project should be run using a JetBrains Runtime other than the default for the IDE Development Instance, specify the JetBrains Runtime version.
- Set the appropriate attributes for patching the
plugin.xml
file.
Plugins Targeting Alternate IntelliJ Platform-Based IDEs
Gradle also supports developing plugins to run in IDEs that are based on the IntelliJ Platform, but are not IntelliJ IDEA. For more information, see the Developing for Multiple Products page of this guide.