How to Build Your First IntelliJ IDEA Plugin: Step‑by‑Step Guide
This tutorial walks you through setting up the development environment, cloning the IDEA Community source, configuring the SDK, creating a simple plugin project, writing a custom action, registering it in plugin.xml, and running the plugin inside a new IDEA instance, all with clear code examples and screenshots.
When writing Java code you often encounter repetitive tasks and wish for a plugin to automate them. This guide shows how to develop an IntelliJ IDEA plugin from scratch.
Development Environment
The required dependencies are:
IntelliJ IDEA Community Edition
IntelliJ IDEA Community Edition source code
Plugin DevKit
IntelliJ Platform SDK
Install IntelliJ IDEA Community Edition
If you already have the Ultimate edition, you still need the Community edition because the commercial version is closed‑source and you cannot debug core code.
Download the Community Edition source
Clone the source repository:
git clone --depth 1 https://git.jetbrains.org/idea/community.git ideaRefer to the official “Check Out And Build Community Edition” guide for building.
Add IDEA JDK
Create an IDEA JDK to run the plugin. On macOS you may need to add /lib/tools.jar to the classpath manually.
Configure IntelliJ Platform SDK
Open File | Project Structure, create a new IntelliJ Platform SDK and set its JDK to the IDEA JDK you just created.
Then add the downloaded IDEA source directory to the SDK so you can debug IDEA’s own code.
First Plugin
Create a simple plugin to learn the complete workflow.
Create a New Project
Select IntelliJ Platform Plugin and set the Project SDK to the plugin SDK you created.
The project contains src and resources directories. The src holds Java code, while resources/META-INF/plugin.xml describes the plugin.
plugin.xml
<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>
<description><![CDATA[Enter short description for your plugin here.]]></description>
<idea-version since-build="145.0"/>
<depends>com.intellij.modules.lang</depends>
<extensions defaultExtensionNs="com.intellij">
<!-- Add extensions here -->
</extensions>
<actions>
<!-- Add actions here -->
</actions>
</idea-plugin>Create a New Action
Define a class extending AnAction and implement actionPerformed:
public class TextBoxes extends AnAction {
public TextBoxes() {
super("Text _Boxes");
}
@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 like any Java application; a new IDEA instance launches with the plugin enabled. Selecting “Text Boxes” shows the input dialog.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Programmer DD
A tinkering programmer and author of "Spring Cloud Microservices in Action"
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
