IDEA插件开发(简单案例助你快速入门)

第一章:开发入门

一、第一种方式(创建IntelliJ Platform Plugin基础环境)

按照官网配置Setting Up a Development Environment | IntelliJ Platform Plugin SDK

idea版本问题,我添加的是jdk11的插件

1. 选择sdk

配置SDK

2. 创建项目

如果缺失下面内容

自己去项目结构里面按照这个格式创建,他就会自动生成📎plugin.xml

3. 核心配置文件讲解

<idea-plugin>
<!--  插件的ID需要保持唯一-->
  <id>com.alex.firstplugin</id>
<!--  插件名称-->
  <name>firstplugin</name>
<!--  版本号-->
  <version>1.0</version>
<!--  作者和提供方信息-->
  <vendor email="1343845235@qq.com" >alex</vendor>

<!--  插件功能描述-->
  <description><![CDATA[
      Enter short description for your plugin here.<br>
      <em>most HTML tags may be used</em>
    ]]></description>

<!--  变更日志-->
  <change-notes><![CDATA[
      Add change notes here.<br>
      <em>most HTML tags may be used</em>
    ]]>
  </change-notes>

<!--  IDEA 支持最低版本号-->
  <!-- please see https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html for description -->
  <idea-version since-build="173.0"/>

  <!-- please see https://plugins.jetbrains.com/docs/intellij/plugin-compatibility.html
       on how to target different products -->
<!--  相关的依赖-->
  <depends>com.intellij.modules.platform</depends>

<!--  拓展的内容-->
  <extensions defaultExtensionNs="com.intellij">
    <!-- Add your extensions here -->
  </extensions>

<!--  菜单动作-->
  <actions>
    <!-- Add your actions here -->
  </actions>

</idea-plugin>

4. 小案例快速入门

  1. 目录结构
  1. FirstAction
package com.alex;

import com.intellij.notification.Notification;
import com.intellij.notification.NotificationDisplayType;
import com.intellij.notification.NotificationGroup;
import com.intellij.notification.Notifications;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.ui.MessageType;

/**
 * @Auther: liwenhao
 * @Date: 2022/5/11 15:07
 * @Description:
 */
public class FirstAction extends AnAction {

    @Override
    public void actionPerformed(AnActionEvent e) {
        NotificationGroup first_plugin_id = new NotificationGroup("first_plugin_id", NotificationDisplayType.BALLOON, true);
        Notification notification = first_plugin_id.createNotification("点击测试", MessageType.INFO);
        Notifications.Bus.notify(notification);

    }
}
  1. 跑起来会有一个IDEA出来

二、 Gradle方式创建

创建引导

New -> Project -> Gradle 选中 Java & IntelliJ Platform Plugin

问题

import com.intellij.openapi.actionSystem.AnAction;
                                        ^
  错误的类文件: /Users/mac/.gradle/caches/modules-2/files-2.1/com.jetbrains.intellij.idea/ideaIC/2021.1.2/47f24d1ca2495e8de3daf528703b86325ee500b1/ideaIC-2021.1.2/lib/platform-api.jar(com/intellij/openapi/actionSystem/AnAction.class)
    类文件具有错误的版本 55.0, 应为 52.0
    请删除该文件或确保该文件位于正确的类路径子目录中。

核心配置说明

<idea-plugin>
    
  <!-- 插件唯一id,不能和其他插件项目重复,所以推荐使用com.xxx.xxx的格式
       插件不同版本之间不能更改,若没有指定,则与插件名称相同 -->
  <id>com.your.company.unique.plugin.id</id>
   
  <!-- 插件名称,别人在官方插件库搜索你的插件时使用的名称 -->
  <name>Plugin display name here</name>
  
  <!-- 插件版本号 -->
  <version>1.0</version>
    
  <!-- 供应商主页和email(不能使用默认值,必须修改成自己的)-->
  <vendor email="support@yourcompany.com" 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>   

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值