• IntelliJ IDEA 2022.2 (Ultimate Edition) plugin插件开发


    1. 创建IDE Plugin工程

    在这里插入图片描述

    2.修改工程iml文件

    这里默认创建的iml文件module type有问题,需要修改为PLUGIN_MODULE

    
    <module type="PLUGIN_MODULE" version="4">
      <component name="DevKit.ModuleBuildProperties" url="file://$MODULE_DIR$/resources/META-INF/plugin.xml" />
      <component name="NewModuleRootManager" inherit-compiler-output="true">
        <exclude-output />
        <content url="file://$MODULE_DIR$">
          <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
          <sourceFolder url="file://$MODULE_DIR$/resources" type="java-resource" />
        content>
        <orderEntry type="jdk" jdkName="IntelliJ IDEA IU-222.3345.118" jdkType="IDEA JDK" />
        <orderEntry type="sourceFolder" forTests="false" />
      component>
    module>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    3.修改build.gradle.kts文件

    替换为aliyun镜像加快构建速度

    repositories {
        maven("https://maven.aliyun.com/nexus/content/groups/public/")
    }
    
    • 1
    • 2
    • 3

    升级org.jetbrains.intellij 版本到最新1.9.0版本,避免采坑

    plugins {
        id("java")
        id("org.jetbrains.intellij") version "1.9.0"
    }
    
    • 1
    • 2
    • 3
    • 4

    4. build项目

    可能因为github请求超时导致如下报错,忽略即可

    
    > Configure project :
    [gradle-intellij-plugin :MyPlugin] Cannot resolve the latest Gradle IntelliJ Plugin version
    org.gradle.api.GradleException: Cannot resolve the latest Gradle IntelliJ Plugin version
    	at org.jetbrains.intellij.utils.LatestVersionResolver$Companion.fromGitHub(LatestVersionResolver.kt:31)
    	at org.jetbrains.intellij.IntelliJPlugin.checkPluginVersion(IntelliJPlugin.kt:135)
    	at org.jetbrains.intellij.IntelliJPlugin.apply(IntelliJPlugin.kt:80)
    	at org.jetbrains.intellij.IntelliJPlugin.apply(IntelliJPlugin.kt:68)
    	at 
    	......
    
    > Task :prepareKotlinBuildScriptModel UP-TO-DATE
    Could not resolve: org.jetbrains:annotations:23.0.0
    Could not resolve: org.jetbrains:annotations:23.0.0
    
    BUILD SUCCESSFUL in 1m 15s
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16

    这里为了节省时间,也可以在第一次build成功后,为了避免后面github请求等待超时时间过长,可以设置为离线模式进行build
    在这里插入图片描述

    5. run起来

    不用添加plugin configution 配置,直接点击gradle run plugin脚本即可
    在这里插入图片描述

    启动成功!
    在这里插入图片描述

    6. 写个demo

    右键直接使用Plugin DevKit插件 new一个Action
    在这里插入图片描述
    生成的action支持直接跳转到对应plugin.xml中配置的地方(对应已经生成好了)
    在这里插入图片描述
    在这里插入图片描述
    补充action代码,测试验证下PsiElement对象获取

    public class MyAction extends AnAction {
    
        @Override
        public void actionPerformed(AnActionEvent e) {
            // TODO: insert action logic here
            Project project = e.getProject();
            PsiElement element = (PsiElement)e.getData(CommonDataKeys.PSI_ELEMENT);
            Messages.showInfoMessage(element.toString(), "Caret Parameters Inside The Editor");
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    点击Run Plugin ,启动完成后Tools工具栏对应出现新增MyAction按钮
    在这里插入图片描述
    点击后,弹出PsiElement非空,说明跑通了
    在这里插入图片描述

  • 相关阅读:
    跨域问题的分析
    java计算机毕业设计在线健康系统设计与实现MyBatis+系统+LW文档+源码+调试部署
    计算机视觉之目标检测训练数据集(皮卡丘)《2》
    大模型Agent最新论文及源码合集,覆盖构建、应用、评估
    elementui-plus el-tree组件数据不显示问题解决
    使用接口根据关键词取亚马逊商品数据
    Shell脚本<<eeooff的使用
    【网络层】IP因特网协议解析
    Ps:RGB 直方图
    【JavaWeb】会话 cookie
  • 原文地址:https://blog.csdn.net/Primary_wind/article/details/126807238