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

﹏ヽ暗。殇╰゛Y 2024-04-05 05:28 149阅读 0赞

1. 创建IDE Plugin工程

在这里插入图片描述

2.修改工程iml文件

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

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

3.修改build.gradle.kts文件

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

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

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

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

4. build项目

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

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

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

5. run起来

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

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

6. 写个demo

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

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

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

发表评论

表情:
评论列表 (有 0 条评论,149人围观)

还没有评论,来说两句吧...

相关阅读