Skip to content

fix: 修复 IDEA 2026.2 下插件不可用及构建依赖无法解析 - #55

Open
ericericlee wants to merge 2 commits into
mars-men:masterfrom
ericericlee:master
Open

fix: 修复 IDEA 2026.2 下插件不可用及构建依赖无法解析#55
ericericlee wants to merge 2 commits into
mars-men:masterfrom
ericericlee:master

Conversation

@ericericlee

Copy link
Copy Markdown

一、构建配置:依赖仓库失效

dl.bintray.com 已关停,gradle-intellij-plugin 0.4.21 依赖的 structure-base:3.105、structure-intellij:3.105、
plugin-repository-rest-client:2.0.6 在 JetBrains 官方源(含 cache-redirector)均已 404,导致 :classpath 配置无法解析。

  • build.gradle:buildscript 与 project 仓库改用阿里云镜像 (public + gradle-plugin,实测仍缓存有上述 artifact), 移除已关停的 bintray 源和用不上的 sonatype snapshots 源
  • settings.gradle:补充 pluginManagement,使 plugins {} 的插件 标记解析同样走镜像,避免卡在 plugins.gradle.org
  • gradlew:补上可执行权限

二、IDEA 2026.2 兼容:EDT 读 PSI 抛 read-action 异常

IDEA 2024 起 EDT 不再隐式持有读锁。JsonDialog 为 JFrame,其按钮
监听器运行在普通 EDT 事件循环中,读取 PSI 时抛
RuntimeExceptionWithAttachments: Read access is allowed from inside read-action only。

将 EDT 上的 PSI 读取统一包入 read action:

  • MainAction#actionPerformed:getPsiFileInEditor / getTargetClass
  • JsonDialog#initGeneratePanel:PsiJavaFileImpl.getPackageName
  • PsiClassUtil:exist / getJavaSrc / getPackageFile / getPackage / isClassAvailableForProject
  • ConvertBridge#collectClassAttribute:getQualifiedName / getAllFields / getAllInnerClasses(异常栈直接现场)

采用 ApplicationManager.getApplication().runReadAction(Computable), 该 API 自旧版本起长期存在且可重入,故嵌套于 WriteCommandAction 中的
调用点同样安全,不影响对旧版 IDEA 的兼容。写操作仍沿用原有的
WriteCommandAction.runWriteCommandAction,未将 ConvertBridge#run 整体包成 read action,以免出现 read action 内启动 write action。

三、IDEA 2026.2 兼容:使用了已被移除的 API

WriteCommandAction$Simple 与 RunResult 在 2026.2 中已删除, DataWriter 继承前者,运行到写入阶段必然 NoClassDefFoundError。

  • DataWriter 改为普通类,写入交由调用方已有的 runWriteCommandAction 包裹(ConvertBridge、FieldsDialog 均已如此)
  • 移除原 Task.Backgroundable:其将写操作放在后台线程执行, 与"写操作必须在 EDT"的约束相悖;结束提示改为 invokeLater 弹出, 避免在写事务内改动 UI

验证:对 2019.3.5 SDK 编译通过(确认未引入新版本专属 API);对
IDEA 2026.2 自带 jar 以 JBR 25 编译全部源码 0 错误,同一检查在改动
前为 6 个错误(均位于 DataWriter)。

ericericlee and others added 2 commits September 4, 2026 18:00
一、构建配置:依赖仓库失效

dl.bintray.com 已关停,gradle-intellij-plugin 0.4.21 依赖的
structure-base:3.105、structure-intellij:3.105、
plugin-repository-rest-client:2.0.6 在 JetBrains 官方源(含
cache-redirector)均已 404,导致 :classpath 配置无法解析。

- build.gradle:buildscript 与 project 仓库改用阿里云镜像
  (public + gradle-plugin,实测仍缓存有上述 artifact),
  移除已关停的 bintray 源和用不上的 sonatype snapshots 源
- settings.gradle:补充 pluginManagement,使 plugins {} 的插件
  标记解析同样走镜像,避免卡在 plugins.gradle.org
- gradlew:补上可执行权限

二、IDEA 2026.2 兼容:EDT 读 PSI 抛 read-action 异常

IDEA 2024 起 EDT 不再隐式持有读锁。JsonDialog 为 JFrame,其按钮
监听器运行在普通 EDT 事件循环中,读取 PSI 时抛
RuntimeExceptionWithAttachments: Read access is allowed from
inside read-action only。

将 EDT 上的 PSI 读取统一包入 read action:

- MainAction#actionPerformed:getPsiFileInEditor / getTargetClass
- JsonDialog#initGeneratePanel:PsiJavaFileImpl.getPackageName
- PsiClassUtil:exist / getJavaSrc / getPackageFile / getPackage /
  isClassAvailableForProject
- ConvertBridge#collectClassAttribute:getQualifiedName /
  getAllFields / getAllInnerClasses(异常栈直接现场)

采用 ApplicationManager.getApplication().runReadAction(Computable),
该 API 自旧版本起长期存在且可重入,故嵌套于 WriteCommandAction 中的
调用点同样安全,不影响对旧版 IDEA 的兼容。写操作仍沿用原有的
WriteCommandAction.runWriteCommandAction,未将 ConvertBridge#run
整体包成 read action,以免出现 read action 内启动 write action。

三、IDEA 2026.2 兼容:使用了已被移除的 API

WriteCommandAction$Simple 与 RunResult 在 2026.2 中已删除,
DataWriter 继承前者,运行到写入阶段必然 NoClassDefFoundError。

- DataWriter 改为普通类,写入交由调用方已有的
  runWriteCommandAction 包裹(ConvertBridge、FieldsDialog 均已如此)
- 移除原 Task.Backgroundable:其将写操作放在后台线程执行,
  与"写操作必须在 EDT"的约束相悖;结束提示改为 invokeLater 弹出,
  避免在写事务内改动 UI

验证:对 2019.3.5 SDK 编译通过(确认未引入新版本专属 API);对
IDEA 2026.2 自带 jar 以 JBR 25 编译全部源码 0 错误,同一检查在改动
前为 6 个错误(均位于 DataWriter)。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant