Idea Plugin

Idea Plugin 我们一直在用。


Quick Start


  • Plugin DevKit

【File】=>【Setting】=>【Plugins】=》【Plugin DevKit】


New Project


new plugin project

  • plugin.xml

创建后会在 resources/META-INF 下有一个插件配置文件。内容如下:

  <name>Plugin display name here</name>
  <vendor email="" url="">YourCompany</vendor>

      Enter short description for your plugin here.<br>
      <em>most HTML tags may be used</em>

      Add change notes here.<br>
      <em>most HTML tags may be used</em>

  <!-- please see for description -->
  <idea-version since-build="145.0"/>

  <!-- please see
       on how to target different products -->
  <!-- uncomment to enable plugin in all products

  <extensions defaultExtensionNs="com.intellij">
    <!-- Add your extensions here -->

      <!-- Add your actions here -->

  • Build Number Ranges

<idea-version since-build="145.0"/>

用于指定插件对应的 idea 版本信息。详情见 Build Number Ranges

Creating an action

  • Project Struct
│          plugin.xml

这个类就是我们定义的 Action。内容如下:

package com.ryo.idea.plugins;

import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;

 * Created by bbhou on 2017/10/13.
public class TextBoxes extends AnAction {
    // If you register the action from Java code, this constructor is used to set the menu item name
    // (optionally, you can specify the menu description and an icon to display next to the menu item).
    // You can omit this constructor when registering the action in the plugin.xml file.
    public TextBoxes() {
        // Set the menu item name.
        super("Text _Boxes");
        // Set the menu item name, description and icon.
        // super("Text _Boxes","Item description",IconLoader.getIcon("/Mypackage/icon.png"));

    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 + "!\n I am glad to see you.", "Information", Messages.getInformationIcon());
  • Register an action

当我们定义好上述 action 之后,需要进行注册。

注册的方式有两种: creating_an_action

(1) 界面操作

  • In your project, on the context menu of the destination package click New or press Alt + Insert.

  • On the New menu, click Action.

(2) 修改 plugin.xml

其中 (1) 实际上是 idea 自动帮我们修改了文件。个人偏向后者。

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

<add-to-group group-id="MainMenu" anchor="last" /> 将在主菜单添加对应菜单栏。

<action id="Myplugin.Textboxes" class="com.ryo.idea.plugins.TextBoxes" text="Text _Boxes" description="A test menu item" />

id 菜单唯一标识。class 为对应的实现类。


和运行普通项目一样。然后就会启动一个新的 idea 窗口,可以在窗口中看到新添加的主菜单信息。

  • To debug a plugin

Select Run/Debug in the main menu, or press Shift + F9.

  • To run a plugin

Select Run/Run in the main menu, or press Shift + F10.

Deploying a Plugin



To deploy a plugin:

  • Make your project by invoking Build / Make Project.

  • Prepare your plugin for deployment. In the main menu, select Build / Prepare Plugin Module <module name> for Deployment.

运行完之后,会生成一个 <module name>.jar 文件。


将上述 jar 文件复制到 .IntelliJIDEAx0\config\plugins, 重启 Idea 将生效。




  • In the main menu, select File/Settings to open the Settings dialog box.

  • In the Settings dialog box, under IDE Settings, click Plugins.

  • In the Plugins area, open the Installed tab, and then select the check-box next to your plugin name.

  • When finished, click OK to close the Settings dialog box.

  • Restart the IDE so that your changes take effect.



publishing plugin