How to Develop an IntelliJ IDEA Plugin: Environment Setup, First Plugin, and Action Creation

This guide walks you through setting up the IntelliJ IDEA development environment, cloning the Community Edition source, configuring the IntelliJ Platform SDK, creating a simple plugin project, writing a custom Action class, registering it in plugin.xml, and running the plugin to see its effect.

Architect's Tech Stack
Architect's Tech Stack
Architect's Tech Stack
How to Develop an IntelliJ IDEA Plugin: Environment Setup, First Plugin, and Action Creation

When developing IntelliJ IDEA plugins you need several dependencies: IntelliJ IDEA Community Edition, its source code, the Plugin DevKit, and the IntelliJ Platform SDK.

Install the Community Edition (if you only have the Ultimate edition) and clone the source from the JetBrains Git repository:

git clone --depth 1 https://git.jetbrains.org/idea/community.git idea

Follow the official Checkout And Build Community Edition guide to build the IDE from source.

Add an IDEA JDK to run the plugin. If you are not on macOS with the official JDK, manually add the /lib/tools.jar to the classpath.

Configure the IntelliJ Platform SDK via File | Project Structure, selecting the IDEA JDK you just created.

Create the first plugin project by choosing IntelliJ Platform Plugin and setting the Project SDK to the plugin SDK you configured. The project contains src (source code) and resources (including META-INF/plugin.xml).

A minimal plugin.xml looks like this:

<idea-plugin>
  <id>com.your.company.unique.plugin.id</id>
  <name>Plugin display name here</name>
  <version>1.0</version>
  <vendor email="[email protected]" url="http://www.yourcompany.com">YourCompany</vendor>
  <idea-version since-build="145.0"/>
  <depends>com.intellij.modules.lang</depends>
  <extensions defaultExtensionNs="com.intellij">
    <!-- Add your extensions here -->
  </extensions>
  <actions>
    <!-- Add your actions here -->
  </actions>
</idea-plugin>

To add functionality, create a custom Action by extending AnAction:

public class TextBoxes extends AnAction {
    public TextBoxes() {
        super("Text _Boxes"); // menu item name, '_' marks shortcut
    }
    @Override
    public void actionPerformed(AnActionEvent event) {
        Project project = event.getData(PlatformDataKeys.PROJECT);
        String txt = Messages.showInputDialog(project, "What is your name?", "Input your name", Messages.getQuestionIcon());
        Messages.showMessageDialog(project, "Hello, " + txt + "!
 I am glad to see you.", "Information", Messages.getInformationIcon());
    }
}

Register the Action in plugin.xml:

<actions>
  <group id="MyPlugin.SampleMenu" text="_Sample Menu" description="Sample menu">
    <add-to-group group-id="MainMenu" anchor="last"/>
    <action id="Myplugin.Textboxes" class="Mypackage.TextBoxes" text="Text _Boxes" description="A test menu item"/>
  </group>
</actions>

After building, run the plugin just like any Java application; a new IDEA instance launches with the plugin enabled. Selecting the "Text Boxes" menu item shows the input dialog and greeting message.

Source: 木杉的博客 (http://imushan.com).

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

actionIntelliJ IDEAPlugin DevelopmentIDE extension
Architect's Tech Stack
Written by

Architect's Tech Stack

Java backend, microservices, distributed systems, containerized programming, and more.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.