Last time we talked about how to prepare the environment of IDEA plug-in development, now we create a demo project, used for simple test environment

If the environment is a problem, look at the previous article to see if it can help, and if it still doesn’t, private messages are welcome.

1. Create an idea Plugin project

Creating a project is as simple as creating a Gradle project. Simply check the IntelliJ platform plugin library

Just note that the project SDK here needs to select the same version of the plug-in development SDK that you prepared earlier

Fill in the corresponding project information and click Finish

2. Build projects

After the creation is successful, the development interface is displayed, and IDEA will build the project.

If this is the first build, there may be a few large dependencies that will be slow to download. If you are not in a hurry, just wait. If the network speed is not good, download timeout, there are other rescue schemes, as follows to make a simple introduction:

2.1 Setting Gradle Domestic Image acceleration

This is very necessary, after setting the image acceleration, the dependency download speed will be greatly improved.

There are two specific methods:

Method 1: The current project takes effect

Add the following configuration under Repositories in the project’s Build. gradle:

repositories {
    maven {
        url "http://maven.aliyun.com/nexus/content/groups/public"}}Copy the code

Method 2: Global Effect If you want global effect, you need to add configuration in gradle directory.

C:\Users\admin.gradle; C:\Users\admin.gradle;

Go to the. Gradle directory, create a new init.gradle file (append to it if you have one) and add the following:

allprojects {
    repositories {
        maven {
            url "http://maven.aliyun.com/nexus/content/groups/public"}}}Copy the code

This way, mirror acceleration is set

2.2 Manually Downloading dependent Files

Because a few dependencies are really large, and the download speed is slow, if the network speed is good, just need to set up the image acceleration, etc., and then build, if the network speed is not good, you can use manual download file after the build. The main large files encountered are as follows:

Gradle-x.x-bin file for manual download:

Gradle-x.x-bin is the first large file that needs to be downloaded at build time.

Stop the automatic construction of IDEA first,

Go to the. Gradle \wrapper\dists folder to see if there is a folder in gradle-x.x-bin or gradle-x.x-all format.

If not, run the following build command in the build.gradle directory in the project folder of your new project until a gradle-x.x-bin or gradle-x.x-all folder appears in the. Gradle \wrapper\dists folder to stop the command execution

gradle build
Copy the code

When. Gradle \ wrapper \ dists folder appears gradle 7.0.x.x – bin or gradle 7.0.x.x – all format folder, enter the folder, at this time there will be a similar “efvqh8uyq79v2n7rcncuhu9sv” such encoding format of the folder, enter again In, delete all files inside

Use the shared url to download the corresponding ZIP package of the folder (be sure to download the corresponding package), and copy the downloaded file to the folder that you just deleted

The gradle-x.x-bin file has already been skipped

Manual download of ideaIC files:

IdeaIC is another slower dependency, as long as there are two folders with things that need to be downloaded manually:

Gradle \ caches \ modules – 2 \ files – 2.1 \ com jetbrains.. Intellij idea \ ideaIC

Gradle \ caches \ modules – 2 \ descriptors \ com \ metadata 2.96 jetbrains.. Intellij idea \ ideaIC

I have version 2020.3.2 on my side. If necessary, you can chat with me privately. I will update the download link of version 2020.3.2 after uploading it. But if it’s another version, you’ll have to wait for it to download

3. Configure the plugin. XML file

Here’s an example

<idea-plugin>
    <id>com.xyz.demo</id>
    <name>Configuration 1: Name of the plug-in</name>
    <vendor email="[email protected]" url="http://www.xxx.com">Your company \ name</vendor>

    <description><! [CDATA[this is the description of the entire project.<br> <em> This is used to describe the functions of your plug-in </em> <em> this is supported by standard HTML tags </em>]]></description>

    <! -- please see https://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/plugin_compatibility.html on how to target different products -->
    <depends>com.intellij.modules.platform</depends>

    <extensions defaultExtensionNs="com.intellij">
        <! -- Add extension here -->
    </extensions>
    
    <change-notes><! [CDATA] <br> <em> To use this tag, you need to delete the patchPluginXml tag in build.gradle file </em> <em> support standard HTML tag </em>]]></change-notes>

    <actions>
        <! Add your action here -->
    </actions>
</idea-plugin>
Copy the code

4. A Demo Action

Select the appropriate package in the project, create a Java file to complete an operation,idea for the creation of idea plug-in operation has a visual creation method, the steps are as follows:

Then fill in the corresponding information, select the parent menu item to be added to, set the shortcut key (optional), and click OK

At this point, you can see that a Java file has been created that implements the AnAction class, and that there is an actionPerformed method that needs to be implemented. This method is the method that implements the logic after we trigger the plug-in action

In addition, the corresponding action configuration is automatically added in plugin.xml

<actions>
        <! Add your action here -->
        <action id="xxx.DemoAction" class="com.xxx.action.DemoAction" text="DemoAction" description="Test operation">
            <add-to-group group-id="ToolsMenu" anchor="first"/>
            <keyboard-shortcut keymap="$default" first-keystroke="shift D"/>
        </action>
</actions>
Copy the code

Once you implement the actionPerformed method, you can do a simple test

@Override
public void actionPerformed(AnActionEvent e) {
	/ / pop up a text box, Messages getInformationIcon () is to obtain an icon icon, can be custom icon
	Messages.showMessageDialog("Test popup contents"."Popup title", Messages.getInformationIcon());
}
Copy the code

5. Run the plug-in

The plugin runs like a normal project,idea will run the plugin by default, just click run

After clicking run, a new idea will pop up (the first one is slow)

View the new idea project Plugin configuration that pops up, and you will find that our custom plugin has been installed

Create or open a project to test our custom plug-in


This is a test environment for the IDEA plug-in project demo, can pop up the test popup indicates that we are ready for plug-in development

In the process of plug-in development, there will be a lot of problems, such as the configuration of action action menu selection and so on

When developing an actual working plug-in, you also need to understand some of the API for plug-in development

These will be shared in the next update