idea插件开发

常见问题

1、Caused by: java.lang.NullPointerException: getHeaderField(“Location”) must not be null

这个问题是网络问题,gradle脱机模式运行即可

2、如果使用新版本创建的插件,会发现是kotlin语言,这时候将kotlin文件夹改为java开发即可

3、Idea 2023.3 以上版本开发,需要安装Plugin DevKit插件

4、开启IDEA内部模式(使用UI检查器定位代码)

文件资源解释

1、plugin.xml

在 IntelliJ IDEA 插件开发中,plugin.xml 文件用于定义插件的元数据和配置信息。其中的 <depends>标签用于声明插件的依赖关系。

src/main/resources/META-INF/plugin.xml 是 IntelliJ IDEA 插件的核心配置文件,它定义了插件的元数据、依赖关系、扩展点和功能。让我详细介绍各个标签的含义:

<idea-plugin>
    <!-- 插件的唯一标识符 -->
    <id>com.seeyon.seeyonplugin.seeyonplugin</id>
    
    <!-- 插件的显示名称 -->
    <name>seeyonCode</name>
    
    <!-- 插件版本 -->
    <version>1.1.0</version>
    
    <!-- 供应商信息 -->
    <vendor email="1634255313@qq.com" url="http://www.wuchaozhi.cn">wuchaozhi</vendor>

    <!-- 插件描述,支持HTML格式 -->
    <description><![CDATA[
        <h3>Seeyon exploit</h3>
        <ul>
            <li>Eclipse now basically generates code and restricts package names to lowercase</li>
            <li>Note: When creating a module, enter the module name with lowercase letters</li>
            <li>The remaining functions are under continuous maintenance</li>
        </ul>

        <h3>中文:致远二次开发插件</h3>
        <ul>
            <li>新版本2023.8 迭代,适配新版本git仓库</li>
            <li>1.0.8 新特性:</li>
            <li>生成自定义maven模块优化</li>
        </ul>
    ]]></description>

    <!-- 变更日志 -->
    <change-notes><![CDATA[
      <p>1.0.8-SNAPSHOT</p>
    ]]></change-notes>
    
    <!-- 插件依赖,声明插件需要哪些模块才能运行 -->
    <depends>com.intellij.modules.platform</depends>
    <depends>com.intellij.modules.lang</depends>
    <depends>com.intellij.modules.java</depends>
    <depends>com.intellij.modules.xml</depends>
    <depends>com.intellij.modules.vcs</depends>

    <!-- 声明插件支持的IDEA版本范围 -->
    <idea-version since-build="203.6682.168"/>
    
    <!-- 插件扩展点,声明插件提供的各种服务和功能 -->
    <extensions defaultExtensionNs="com.intellij">
        <!-- 配置界面 -->
        <applicationConfigurable instance="com.seeyon.apps.ui.ColdConfigurable"/>
        
        <!-- 服务定义 -->
        <applicationService serviceInterface="com.seeyon.apps.service.GenerateService"
                            serviceImplementation="com.seeyon.apps.service.impl.GenerateServiceImpl"/>
        <applicationService serviceInterface="com.seeyon.apps.storage.ApplicationSettingStorage"
                        serviceImplementation="com.seeyon.apps.storage.ApplicationSettingStorage"/>
        <applicationService serviceInterface="com.seeyon.apps.storage.SettingsStorage"
                        serviceImplementation="com.seeyon.apps.storage.SettingsStorage"/>
        
        <!-- 通知组 -->
        <notificationGroup id="Custom Notification Group"
                           displayType="BALLOON"/>
        
        <!-- 启动活动 -->
      // 这个是基于组件方式,而组件已经被官方弃用,现有的所有组件都应被转换为服务、扩展模块或监听器形式(详见下文)
        <postStartupActivity implementation="com.seeyon.apps.MyPluginStartupActivity"/>
    </extensions>
    
    <!-- 插件的动作(菜单项、快捷键等) -->
    <actions>
        <!-- 右键生成模板 -->
        <action id="frstAction" class="com.seeyon.apps.action.Seeyonplugin" text="Seeyon add module" description="生成模块代码">
            <add-to-group group-id="ProjectViewPopupMenu" anchor="after" relative-to-action="WeighingNewGroup"/>
        </action>
        <!-- 右键生成补丁 -->
        <action id="compileTemAction" class="com.seeyon.apps.action.CompileTemAction" text="Seeyon build Patch" description="生成V5补丁">
            <add-to-group group-id="ProjectViewPopupMenu" anchor="after" relative-to-action="frstAction"/>
        </action>
    </actions>
    
    <!-- 资源包,用于国际化 -->
    <resource-bundle>messages.messages</resource-bundle>
</idea-plugin>

重要但你的项目中没有的标签:

  1. <category> - 插件分类
<category>Custom Development</category>
  1. until-build - 限制插件支持的最高版本
<idea-version since-build="203.6682.168" until-build="251.*"/>
  1. <depends optional="true" config-file="..."> - 可选依赖
<depends optional="true" config-file="optionalPlugin.xml">com.third.party.plugin</depends>
  1. <module> - 声明插件模块类型
<module type="PLUGIN_MODULE" version="4"/>
  1. <product-descriptor> - 指定插件适用的产品
<product-descriptor since-build="203.6682.168" until-build="251.*"/>

这个文件是插件的"身份证",告诉IDEA平台插件的基本信息、依赖关系、提供的功能以及如何与其他组件交互。

2、IC和IU

IU(IntelliJ IDEA Ultimate)和IC(IntelliJ IDEA Community)是不同的版本,它们的API和功能集有所不同。

IU(Ultimate版)包含更多的商业功能和插件,而IC(Community版)是开源版本。

虽然它们共享大部分核心API,但在某些特定功能和API上可能存在差异。

在你的项目中,你使用的是 create("IC", "2025.1.4.1"),这意味着你正在使用IntelliJ IDEA Community Edition 2025.1.4.1版本的API。这个版本可能不包含IU版本中的某些特定API或实现。

如果你需要IU版本中的特定功能,可以考虑:

// ... existing code ...
dependencies {
    intellijPlatform {
        create("IU", "2025.2.3")  // 使用IU版本而不是IC版本
        testFramework(org.jetbrains.intellij.platform.gradle.TestFrameworkType.Platform)

        // Add necessary plugin dependencies for compilation here, example:
        // bundledPlugin("com.intellij.java")
    }
}
// ... existing code ...

注意:将版本改为IU(Ultimate版)可能会引入仅在商业版本中可用的API,这可能会影响插件的兼容性。如果你的插件需要发布到JetBrains插件仓库,通常建议使用IC版本以确保更广泛的兼容性。

这是点击关于显示的信息:

IntelliJ IDEA 2025.2.5 (Ultimate Edition) // 2025.2.5是产品版本号
Build #IU-252.28238.7, built on November 20, 2025 //IU-252.28238.7是内部构建版本号
Source revision: 7059016f3609e
授权给 signup scooter
您有此版本的永久回退许可证。
订阅有效期至 2099年12月31日。
Runtime version: 21.0.9+10-b1038.76 aarch64 (JCEF 122.1.9)
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Toolkit: sun.lwawt.macosx.LWCToolkit
macOS 15.5
GC: G1 Young Generation, G1 Concurrent GC, G1 Old Generation
Memory: 5104M
Cores: 12
Metal Rendering is ON
Registry:
  debugger.new.tool.window.layout=true
  ide.experimental.ui=true
  ide.experimental.ui.inter.font=true
Non-Bundled Plugins:
  JavaScriptDebugger (252.28238.33)
  com.intellij.notebooks.core (252.28238.9)
  com.github.yuyuanweb.mianshiyaplugin (0.5.6)
  Subversion (252.28238.33)
  com.intellij.copyright (252.28238.33)
  org.editorconfig.editorconfigjetbrains (252.28238.22)
  org.jetbrains.plugins.yaml (252.28238.33)
  PythonCore (252.28238.7)
  org.toml.lang (252.28238.9)
  com.intellij.kubernetes (252.28238.33)
  DevKit (252.27397.28)
  name.kropp.intellij.makefile (252.25557.77)
  com.intellij.properties (252.28238.9)
  com.intellij.velocity (252.28238.9)
  com.anthropic.code.plugin (0.1.14-beta)
  Key Promoter X (2024.2.2)
  jclasslib (7.0)
  GsonFormatPlus (1.6.1)
  com.github.wangji92.arthas.plugin (2.50)
  com.intellij.uiDesigner (252.27397.28)
  com.liubs.jaredit (2.3.6)
  String Manipulation (9.16.0)
  com.seeyon.seeyonplugin.seeyonplugin (1.1.0-SNAPSHOT)
  com.alibaba.p3c.xenoamess (2.2.3.0x)
  com.intellij.swagger (252.28238.33)
  com.jetbrains.restClient (252.28238.33)
  Pythonid (252.28238.7)
  intellij.jupyter (252.28238.22)
  Docker (252.28238.33)
  PlantUML integration (7.13.0-IJ2023.2)
  org.jetbrains.plugins.gitlab (252.28238.33-IU)
  org.jetbrains.plugins.github (252.28238.33-IU)
  MavenRunHelper (4.30.0-IJ2022.2)
  JavaScript (252.28238.29)
  com.sjhy.plugin.easycode (1.2.9-java.RELEASE)
  com.intellij.react (252.28238.29)
  com.intellij.angularjs (252.23892.298)
  com.bruce.intellijplugin.generatesetter (2.8.4)
  izhangzhihao.rainbow.brackets.lite (1.3.0)
  com.alibabacloud.intellij.cosy (2.6.8)
  com.hxl.plugin.cool-request (2025.11.11)
  org.jetbrains.plugins.vue (252.28238.32)
  cn.yiiguxing.plugin.translate (3.8.1)
  com.intellij.mcpServer (252.28238.29)
  org.jetbrains.security.package-checker (252.28238.22)
  com.baomidou.plugin.idea.mybatisx (1.7.4)
  com.intellij.microservices.ui (252.28238.33)
Kotlin: 252.28238.7-IJ

如果一些API报错,增加依赖的地方为:

// build.gradle.kts

dependencies {
    intellijPlatform {
        create("IC", "2025.1.4.1")
        testFramework(org.jetbrains.intellij.platform.gradle.TestFrameworkType.Platform)

        // Add necessary plugin dependencies for compilation here, example:
        bundledPlugin("com.intellij.java")
    }
}

常见开发方式

1、通知组

plugin.xml 定义一个<notificationGroup> 标签用于在IntelliJ IDEA中定义一个通知组,它的作用是:

  1. 创建通知通道:定义一个专门的通知通道,用于显示插件产生的各类通知消息

  2. 统一管理通知:将插件的所有通知归类到这个组中,便于管理和控制

  3. 自定义通知行为:可以指定通知的显示类型和行为

在你的代码中:

<notificationGroup id="Custom Notification Group" displayType="BALLOON"/>
  • id="Custom Notification Group":定义了通知组的唯一标识符,你的代码可以通过这个ID来发送通知
  • displayType="BALLOON":指定通知的显示类型为气泡弹窗(BALLOON),这是一种常见的通知显示方式,会在IDE的右下角显示一个小气泡提示

在代码中使用这个通知组的例子:

NotificationGroupManager.getInstance()
    .getNotificationGroup("Custom Notification Group")  // 使用相同的ID
    .createNotification("消息内容", NotificationType.INFORMATION)
    .notify(project);

这种设计让你的插件可以向用户显示各种通知消息(如操作成功、错误提示、警告等),并且所有来自你插件的通知都会通过这个统一的通道进行管理。