Child pages
  • Getting Started with Plugin Development

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

The use of plugins allows you to extend the IntelliJ IDEA functionality. This topic provides information on how to develop and publish your custom plugins. The following subjects are covered:

Preliminary Steps
Configuring IntelliJ IDEA SDK
Creating a new plugin module
Creating an action
Running and debuging a plugin
Deploying a plugin
Publishing a plugin to plugin repository

...

Preliminary Steps

Use the following check list to ensure that you are ready to develop your custom plugins.

Item to check

Description

IntelliJ IDEA

IntelliJ IDEA version 9.0 or later, either Community Edition or Ultimate, must be installed on your computer.

Sources of IntelliJ IDEA Community Edition

The sources of IntelliJ IDEA Community Edition should be checked out to your local computer. This is not a requirement but will make it much easier for you to debug your plugins.
You can check out the sources either by using IntelliJ IDEA or from the command line. For detailed instructions, refer to Check Out & Build Community Edition.

IntelliJ IDEA SDK

Development of your plugins requires the IntelliJ IDEA SDK to be configured for your IDEA project. For more information, see Configuring IntelliJ IDEA SDK below.

Plugin DevKit

Please make sure that the "Plugin DevKit" plugin is enabled in Settings | Plugins.

...

Configuring IntelliJ IDEA SDK

Development of your custom plugins requires the IntelliJ IDEA SDK to be installed and configured for your project.

To configure Intellij IDEA SDK

  1. On the main menu, choose File | Project Structure. Alternatively, do one of the following:
    • Press CTRL + ALT + SHIFT + S
    • On the toolbar, click Image Removed
  2. In the Project Structure dialog box that opens, do the following, and then click OK:
    • Under Platform Settings, click SDKs, and then click the plus sign icon.
    • From the provided list, select IntelliJ IDEA Plugin SDK.
    • Using the Select Path dialog box that opens, select the IntelliJ IDEA installation directory directory, and then click OK. Note, that by default, this dialog box automatically selects the home directory of the currently running IntelliJ IDEA installation.
    • In the Select internal Java platform dialog box that opens, select a Java SDK (JDK 1.6 is recommended) to be used as IDEA internal platform, and then click OK.
    • Optionally, in Sandbox Home, change the default folder to which Intellij IDEA will copy plugins for debugging.
    • Open the Sourcepath tab, click Add, and then select the folder where you have checked out the sources of IntelliJ IDEA Community Edition.
    • In the Detected Source Roots dialog box that opens, click OK.

...

Creating a new plugin module

This section explains how you can create a new plugin module from a scratch using the New Project wizard. Optionally, you can import an existing project or import a project from external models. You can also add a new plugin module to an existing Intellij IDEA project. For more information, refer to Intellij IDEA Web Help .

To create a plugin module

  1. On the main menu, choose File | New Project.
    The New Project wizard starts.
  2. On the starting page, select Create new project from scratch and click Next to proceed with the wizard.
    The wizard displays the Settings page.
  3. On the Settings page, do the following:
    • In Name, enter the name of your Intellij IDEA project to be created.
    • In Project files location, specify the location of the source files to be used to create the project from.
      Note that this path is also used to keep the IntelliJ IDEA project files that depend on the project storage format.
    • From the Project storage format, select the format in which you want to store your project.
      Note that the project can be stored in one of the following formats: file-based or directory-based. For more information about these formats, refer to Intellij IDEA Web Help .
    • Select the Create module check box.
      This creates a project with an initial module, with the name and type you can define in the Module Settings area. If you leave this check box cleared, the wizard creates an empty project, but you can create modules later.
    • In Name under Module Settings, enter the name of your plugin module.
    • In Content root, specify the path to the content root of the module.
    • In Module file location, specify the path to the folder where the *.iml file will be stored.
    • Under Select type, select Plugin Module, and then click Next to proceed to the Sources page.
  4. On the Sources page, select one of the following options, and then click Next to proceed to the SDK Selection page:
    • Create source directory: creates a directory that will be marked as the source root in the new project. Enter the directory name, or click the ellipsis button and locate the desired directory in the Select Path dialog box.
    • Do not create source directory: Omits creating the source directory. When selected, an empty project will be created. You can add content roots later.
  5. On the SDK Selection page, under Project JDK, select the Intellij IDEA Plugin SDK to be set for your plugin module, and then click Finish to complete the wizard.

...

Creating an action

Your plugins can customize the Intellij IDEA UI by adding new items to the menus and toolbars. Intellij IDEA provides the AnAction class whose actionPerformed method is called each time you select a menu item or click a toolbar button.
To customize Intellij IDEA, you should perform two basic steps:

  1. In your plugin, define an action or a system of actions that add their own items to menus and toolbars.
  2. Register your actions.

This topic outlines the above steps. For detailed information and samples, refer to IntelliJ IDEA Action System.

Defining actions

An action is a class derived from the AnAction class. To define your action, in your plugin, create a Java class derived from the AnAction class. In this class, override the actionPerformed method to be called when a menu item or a toolbar button is selected.
To clarify this procedure, consider the following code snippet of a .java file that defines the TextBoxes class derived from the AnAction class:

Code Block

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());
}



}

Note that optionally, you can define a set of classes derived from the AnAction class. In this case, your plugin will define a system of actions.

...

Registering actions

Once you have defined an action or a system of actions, you must register them to specify the menu items or toolbar buttons associated with actions.
You can register actions in one of the following ways:

  • Register actions in the <actions> section of the plugin.xml file.
  • Register actions from Java code.

This section provides some examples that illustrate how to register actions. For more information, refer to IntelliJ IDEA Action System.

Registering actions in the plugin.xml file

To register your actions, make appropriate changes to the <actions> section of the plugin.xml file for your IDEA project. The following fragment of the plugin.xml file adds the Sample Menu group (item) to the main menu. Clicking this item allows you to access the Sample Menu | Text Boxes and Sample Menu | Show Dialog menu commands:

Image Removed

Code Block

<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" />
       <action id="Myplugin.Dialogs" class="Mypackage.MyShowDialog" text="Show _Dialog" description="A test menu item" />
     </group>

  </actions>

This fragment of the plugin.xml file demonstrates only some elements you can use in the <actions> section to register your actions. For information about all elements designed to register your actions, refer to IntelliJ IDEA Action System.

Registering actions from Java code

...

Quick creation of actions

IntelliJ IDEA provides the New Action wizard that suggests a simplified way of creating actions, with all the required infrastructure. The wizard helps you declare the action class and automatically makes appropriate changes to the <actions> section of the plugin.xml file.

Note that you can use this wizard only to add a new action to an existing action group on the main menu or toolbar. If you want to create a new action group, and then add an action to this group, follow instructions in Creating an action and Registering Actions earlier in this document.
To create and register an action with the New Action wizard

  1. In your project, on the context menu of the destination package click New or press ALT + INSERT.
  2. On the New menu, click Action.
    Image Removed
  3. On the New Action page that opens, fill in the following fields, and then click OK:
    • Action ID: Enter the unique ID of the action. Recommended format: <Plugin name>.<ID>
    • Class Name: Enter the name of the action class to be created.
    • Name: Enter the name of the menu item or tooltip for toolbar button associated with action.
    • Description: Optionally, enter the action description. The IDEA status bar indicates this description when focusing the action.
    • In the Add to Group area, under Groups, Actions and Anchor, specify the action group to which to add a newly created action, and the position of the newly created action relative to other existing actions.
    • In the Keyboard Shortcuts area, optionally, specify the first and second keystrokes of the action.

Image Removed

IntelliJ IDEA generates a .java file with the specified class name, registers the newly created action in the plugin.xml file, adds a node to the module tree view, and opens the created action class file in the editor.

Sample plugin

A sample plugin that illustrates how to create your own action group and add it to the main menu and to the main toolbar is available in the <%IDEA project directory%>/samples/actions directory.

...

Running and debugging a plugin

IntelliJ IDEA allows you to run and debug a plugin wthout leaving the IDE. To run or debug the plugin from within IntelliJ IDEA, you need a configured special profile (a Run/Debug configuration) that specifies the class to run, VM parameters and other specific options. In most cases, you can use default Run/Debug configuration profiles for your plugin projects. For information on how to change the Run/Debug configuration profile, refer to Run/Debug Configuration and Run/Debug Configuration: Plugin in Intellij IDEA Web Help.
Using the IntelliJ IDEA's debugger, you can find out the origin of the run-time errors and exceptions.

To debug a plugin

  • On the main menu, choose Run | Debug or press Shift + F9.

To run a plugin

  • On the main menu, choose Run | Run or press Shift + F10.

...

Deploying a plugin

To use your custom plugin, it must be built, installed, and then enabled using Plugin Manager . This section outlines steps to deploy your plugins.

To deploy a plugin

  1. Make your project.
    To make your project, do one of the following:
    • On the main menu, choose Build | Make Project.
    • Press CTRL +F9.
  2. Prepare your plugin for deployment. To do this, on the main menu, choose Build | Prepare Plugin Module <module name> for Deployment.
    This creates a .jar or .zip archive file to be used to install and publish your plugin. If the plugin module does not depend on libraries, the .jar archive will be created. Otherwise, a .zip archive will be created that will include all the plugin libraries specified in the project settings.
  3. Copy the newly created archive file to the ".IntelliJIDEAx0\config\plugins" folder, and then restart Intellij IDEA for changes to take effect.
  4. On the main menu, choose File | Settings. Alternatively, you can press CTRL + ALT + S.
    The Settings dialog box opens.
  5. In the Settings dialog box, under IDE Settings, click Plugins.
  6. 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.
  7. For your changes to take effect, restart Intellij IDEA.

...

Publishing a plugin to plugin repository

When your plugin is ready, you might want to upload it to Intellij IDEA Plugin Repository . To perform this operation, you should login to Intellij IDEA Plugin Repository with your personal JetBrains account.

To get your JetBrains account

  1. Open the JetBrains Account Center web page at http://account.jetbrains.com and click Create Account.
  2. Fill in all fields in the Create Jetbrains Account form that opens and click Register.

To upload your plugin to Intellij IDEA Plugin Repository

  1. Login to Intellij IDEA Plugin Repository at http://plugins.intellij.net/space with your personal JetBrains account.
  2. On your Profile page that opens, click Add new plugin.
  3. Fill in the Add new plugin form that opens and click the Add the plugin button to upload your plugin.

Using CI-Servers

Links to relevant discussion threads
How to build a plugin on a public hosted Continuous Integration server?
How to automate testing for IDEA plugins

Redirect
locationhttp://www.jetbrains.org/intellij/sdk/docs/basics/getting_started.html