Table of contents
Develop plug-in process (simplest usage scenario)
Deploy IntelliJ Platform Plugin SDK
I used to think that the people who developed the idea were really good. Later, when I used various plug-ins in my work, I couldn’t help but sigh, what kind of stuff are these plug-ins, who developed them, they are really amazing~
Now, according to the leader's arrangement, I have to change the company's plug-in~~~
Why develop idea plugins?
The existing plug-ins do not really fully meet your needs. To give a simple chestnut, for example, after tomcat deploys the application, I want to clear the application under weapps, what should I do?
Develop plug-in process (simplest usage scenario)
Environment preparation: jdk11, idea
Deploy IntelliJ Platform Plugin SDK
IntelliJ Platform Plugin SDK is the SDK for developing IntelliJ platform plug-ins, which runs on the JDK
- Navigate to File -> Project Structure, select SDKs under Platform Settings in the left column of the dialog
- Click the + button, first select JDK, specify the path of JDK; then create IntelliJ Platform Plugin SDK, specify the home path as the installation path of IDEA, as shown in the figure
3. After creating the IntelliJ Platform Plugin SDK, select Projects under Project Settings on the left column, and select the newly created IntelliJ Platform Plugin SDK under Project SDK.
Create a plugin project
The project is created successfully, the project directory is as follows, plugin.xml is the core configuration file:
Core configuration (plugin.xml) file description:
<idea-plugin>
<!-- 插件唯一id,不能和其他插件项目重复,所以推荐使用com.xxx.xxx的格式
插件不同版本之间不能更改,若没有指定,则与插件名称相同 -->
<id>com.your.company.unique.plugin.id</id>
<!-- 插件名称,别人在官方插件库搜索你的插件时使用的名称 -->
<name>CJPlugin</name>
<!-- 插件版本号 -->
<version>1.0</version>
<!-- 供应商主页和email(不能使用默认值,必须修改成自己的)-->
<vendor email="[email protected]" url="http://www.yourcompany.com">YourCompany</vendor>
<!-- 插件的描述 (不能使用默认值,必须修改成自己的。并且需要大于40个字符)-->
<description><![CDATA[
Enter short description for your plugin here.<br>
<em>most HTML tags may be used</em>
]]></description>
<!-- 插件版本变更信息,支持HTML标签;
将展示在 settings | Plugins 对话框和插件仓库的Web页面 -->
<change-notes><![CDATA[
Add change notes here.<br>
<em>most HTML tags may be used</em>
]]>
</change-notes>
<!-- 插件兼容IDEAbuild 号-->
<idea-version since-build="173.0"/>
<!-- 插件所依赖的其他插件的id -->
<depends>com.intellij.modules.platform</depends>
<extensions defaultExtensionNs="com.intellij">
<!-- 声明该插件对IDEA core或其他插件的扩展 -->
</extensions>
<!-- 编写插件动作 -->
<actions>
</actions>
</idea-plugin>
复制代码
Enable Plugin DevKit
Plugin DevKit is a plugin for IntelliJ that uses IntelliJ IDEA's own build system to provide support for developing IDEA plugins. Plugin DevKit needs to be installed and enabled before developing IDEA plugins.
Open IDEA, navigate to Settings | Plugins, if there is no Plugin DevKit in the plugin list, click Install JetBrains plugin, search and install.
Create an action action
After the action is created, the configuration will be automatically generated in the plugin.xml configuration file
write action
package com.cjian.ideaplugin;
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;
/**
* @Author: cjian
* @Date: 2022/9/22 19:43
* @Des:
*/
public class ClearAction extends AnAction {
private static final String MESSAGE = "Sure to clear hot deploy?";
@Override
public void actionPerformed(AnActionEvent event) {
// TODO: insert action logic here
Project project = event.getData(PlatformDataKeys.PROJECT);
int txt = Messages.showOkCancelDialog(MESSAGE, "Clear hotDeploy", Messages.getOkButton(), Messages.getCancelButton(), Messages.getInformationIcon());
Messages.showMessageDialog(project, String.valueOf(txt), "Result", Messages.getInformationIcon());
}
}
Just like my normal debugging of java code, you can also set a breakpoint where you need it. I won’t demonstrate it here. Let’s just look at the packaging
Packaging plugins
If the plugin does not depend on any library, the plugin will be packaged into one .jar
, otherwise it will be packaged into one .zip
, zip contains all plugin dependencies
Plug-in package of jar type:
PluginDemo.jar/ com/foo/... ... ... META-INF/ plugin.xml
Plug-in package of zip type:
PluginDemo.zip/ lib/ libfoo.jar libbar.jar PluginDemo.jar/ com/foo/... ... ... META-INF/ plugin.xml
Installation and use are the same
install plugin
After installation, restart idea
Effect:
At this point, I know what a plug-in is, and it can be regarded as a special "project"~