How to Build Your Own IntelliJ IDEA Plugin: Step‑by‑Step Guide
This tutorial walks you through setting up the development environment, configuring the IntelliJ Platform SDK, creating a simple plugin project, adding a custom Action, and running the plugin, providing all necessary code snippets and screenshots for building IntelliJ IDEA plugins.
When writing Java code you often encounter repetitive tasks, and an IDEA plugin can automate them. This guide explains how to set up the development environment, install IntelliJ IDEA Community Edition, obtain its source code, configure the IntelliJ Platform SDK, and create a simple plugin project.
The required dependencies are IntelliJ IDEA Community Edition, its source code, Plugin DevKit, and the IntelliJ Platform SDK. Clone the community source from GitHub with:
git clone --depth 1 git://git.jetbrains.org/idea/community.git ideaConfigure the SDK by adding a new IntelliJ Platform SDK in File | Project Structure, selecting the previously created IDEA JDK, and attaching the IDEA source directory.
Create the first plugin by selecting IntelliJ Platform Plugin as the project type and using the plugin SDK you just configured. The project contains src (code) and resources (plugin resources) directories. A minimal plugin.xml looks like:
<idea-plugin>
<id>com.yourcompany.unique.plugin.id</id>
<name>Plugin display name here</name>
<version>1.0</version>
<vendor>YourCompany</vendor>
<idea-version since-build="145.0"/>
<extensions defaultExtensionNs="com.intellij"/>
<actions/>
</idea-plugin>To add functionality, create a custom Action by extending AnAction and overriding actionPerformed. Example Action class:
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>Run the plugin by launching the project; a new IDEA instance starts with the plugin loaded. Click the newly added “Text Boxes” menu item to see the input dialog in action.
Reference materials: "Setting Up a Development Environment" and "How to make an IntelliJ IDEA plugin in less than 30 minutes".
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.
Java Backend Technology
Focus on Java-related technologies: SSM, Spring ecosystem, microservices, MySQL, MyCat, clustering, distributed systems, middleware, Linux, networking, multithreading. Occasionally cover DevOps tools like Jenkins, Nexus, Docker, and ELK. Also share technical insights from time to time, committed to Java full-stack development!
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.
