IDEA plug-in development, how do I move the company's publishing system to IDEA

It has to be said that JetBrains is very direct. Every programmer can find his own development tool on the official website of JetBrains. These development tools have brought us great convenience in our work. A variety of basic plug-ins, third-party plug-ins, who really knows, fast code prompt, syntax detection, and more importantly, many UI plug-ins are provided. Once upon a time, I thought I could develop an IDEA plug-in myself. Finally, after more than a week's exploration, I could develop a plug-in carelessly! I believe that after reading this article, you can also develop your own plug-in!

What am I going to do?

First, let's introduce our deployment environment process

  • test
  • Beta
  • Grayscale
  • formal

Then, our normal code release process is to merge the development node into an environment branch, and then deploy it using the deployment system! In short, there are two processes,

1. Merge branch

2. Release code

So for these two actions, we will develop such a plug-in to do all the above things directly in the IDEA.

Installation environment

There are many online tutorials, most of which are stereotyped and copied from each other! There are official tutorials, but I can't understand the official documents anyway! Just use the IDEA we currently use,

New - > project, select the three drawn on the figure, and then fill in the basic information, package name, etc. Then wait to build the Gradle project.

After building, you must reconfigure the SDK

To build a plug-in SDK, just follow the steps, because we want to use the plug-in SDK to develop plug-ins, and the native SDK can't meet us!

Students who are a little slow can configure the next two parameters, which I also saw on the Internet,

  • In the ~ /. gradle/ file, find org.gradle.daemon=true. If there is no file, just create one.

  • Modify build.gradle

    repositories {
    		// Add this address
        maven { url "" }


This file, the POM file of Maven type, manages the configuration of the project. Focus on several important areas, others do not affect the development process. You can compare your initial project.

//Project dependency I loaded hutool/okttp/lombok
dependencies {
    implementation 'cn.hutool:hutool-all:5.7.14'
    implementation "com.squareup.okhttp3:okhttp:3.3.1"

    compileOnly group: 'org.projectlombok', name: 'lombok', version: '1.18.20'
    annotationProcessor group: 'org.projectlombok', name: 'lombok', version: '1.18.20'

    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'

//The update log will be displayed in the plug-in introduction.
patchPluginXml {
    changeNotes = """
        <li>Support publishing code</li>
        <li>Support task execution</li>


This is the place to configure plug-in functions, which is a bit similar to the Xml file of Spring managed Bean! Just open it yourself. I'll introduce it in detail later in the actual combat. Normally, an initial plug-in project is similar to the following!

actual combat

This time I want to make such a plug-in!

Because our publishing system needs to log in, I added an operation to authorize the Token, that is, to get the Token and put it in the cache.

Some people say it's not unnecessary? Log in to the system and release it. It's done! But in my opinion, the result of things is not important, the important thing is the process!

Three actions

First, we need to authenticate. When we get the Token and save it to the cache, then select the node to publish the task to the corresponding environment, and finally review the task just submitted. Then the next steps are as follows!

1. Authorization Token

2. Release code

3. Audit code

I believe that programmers have a little understanding of the three swordsmen of the web page. The basic construction of the web page or the basic composition of the App page, the plug-in of IDEA is also similar to the design IDEA, but the language is changed and the implementation process is different!

To write GUI programs in Java, we need to understand the basic tool classes of Java Swing , a GUI toolkit designed for Java. It provides many basic components: for example, text boxes, buttons, separate panes and tables.

Interface coding

The DialogWrapper class in the SDK provides us with a standard page component framework. We implement this class. In most cases, we can implement some methods of this class. Almost all of our components above are based on this class. The difference is that we only need to implement different components!

Writing interface

 * @author Savey
 * @date 2021/10/19 21:50
public class LoginFormDialog extends DialogWrapper {

    private final Project project;

     * Text box
    private final JTextField userText = new JTextField(20);

     * Password box
    private final JPasswordField passwordText = new JPasswordField(20);

    public LoginFormDialog(@Nullable Project project) {
        this.project = project;
        setTitle("Authorized login");
        setSize(350, 200);

     * Core method, creating UI panel in the middle part, and Jpanel can be regarded as DIV box model
    protected @NotNull JComponent createCenterPanel() {
       final JPanel panel = new JPanel();
      	//Cache record
        PropertiesComponent cache = project.getService(PropertiesComponent.class);
        /* We won't introduce more about the layout

        // Create JLabel
        JLabel userLabel = new JLabel("Account  :");
        /* This method defines the location of the component.

         * Create a text field for user input

        // Enter the text field for the password
        JLabel passwordLabel = new JLabel("Password:");

         * This is similar to the text field used for input

        return panel;

    protected void doOKAction() {
     			//Here, when you click OK, we will call the API to get TOKEN and put it into the cache!
      		//Form validation.....
      		//Here, just like writing ordinary Java code, create a Service and call a method.
      	  //Operation UI

In fact, I have also written this interface for a long time, referring to a lot of materials, mainly referring to the teaching of W3C, which is roughly the same way! A little wordy!

One of the difficulties encountered in writing is Table! Debugging for a long time~~~

Create action

Next, create an action to pop up the authorization pop-up box in the current IDEA!

New -> Plugin DevKit ->Action->OK

After clicking OK, IDEA will automatically generate the following code in Plugin.xml.

  	<action popup="true" class="cn.qmai.idea.action.LoginDialogAction" text="to grant authorization Token" description="land Opms" id="loginDialogAction" />

A < Action > tag represents an Action.

 * @author Savey
 * @date 2021/10/19 18:10
public class LoginDialogAction extends AnAction {

    public void actionPerformed(@NotNull AnActionEvent e) {
      	//For the current Project, IDEA is an application. One application can open multiple projects. The Project object corresponds to the currently open Project.
        Project project = e.getProject();
        assert project != null;
      	// LoginFormDialog instance
        DialogWrapper formDialogIns  =	new LoginDialogAction(project);
      	//Display interface;

Put the action on the corresponding menu

       <action popup="true" class="cn.qmai.idea.action.LoginDialogAction" text="to grant authorization Token" description="land Opms" id="loginDialogAction" />
        //I set up a Group here. I put all the actions in my Group, and then put the Group on the ToolsMenu//
        <group popup="true" id="qmOmpsActionGroup" text="Opms assistant" icon="QmOpmsIcons.QmOpmsMenuActions">
            <reference ref="loginDialogAction" />
            <add-to-group group-id="ToolsMenu" anchor="last" />

The < group > label means a group, that is, a group of buttons and a group of actions! Obviously, I put the < action > tag in it. Similar to Spring's Bean.xml!

The < add to Group > tag puts the current tag on the specified Group. I put it on the ToolsMenu (Toosl of IDEA) (as for other Group sentences of the system, they are officially introduced. See what you use!). Of course, you can also specify a custom < action > or < Group > id.

In addition, you may add shortcut keys for each Action

  <action popup="true" id="publishProject" class="cn.qmai.idea.action.PublishProjectAction" text="Release code" description="Release code">
            <keyboard-shortcut keymap="$default"
                               first-keystroke="shift ctrl I"/>

Adding a hotkey to the tag < keyboard shortcut > may conflict with the system. You can modify it in the KeyMap!


This is the same as the usage on the IDEA. Click RUN to open a built-in IDEA for debugging! The DEBUG code is the same as the common IDEA, and there is no difference

Code directory

There are still many knowledge points that have not been released, but these things are enough to write a simple plug-in. Interested students can communicate together! Because many private things are integrated into the code, the source code will not be released!

Tags: Java IDEA

Posted on Fri, 29 Oct 2021 07:20:40 -0400 by richardk1