• 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非空,说明跑通了
    在这里插入图片描述

  • 相关阅读:
    Enterprise Architect15(EA) 工具栏,隐藏后显示快捷方式
    动态IP和静态IP哪个安全,该怎么选择
    私域流量对企业的好处
    《软件方法》自测题解析-004:不能从设计映射需求
    目前世界上有多少种编程语言
    PyTorch DataLoader整理函数详解【collate_fn】
    基于Android的英语学习软件/英语学习系统
    pandas学习笔记
    微服务实践之网关(Spring Cloud Gateway)详解-SpringCloud(2021.0.x)-3
    在线问诊 Python、FastAPI、Neo4j — 问题咨询
  • 原文地址:https://blog.csdn.net/Primary_wind/article/details/126807238