更新IDEA后插件开发提示com.intellij.psi.PsiElement依赖缺失冲突怎么解决
问题根因
你的项目存在三处配置不匹配的问题,共同导致了PsiElement类无法找到:
- JDK版本和IDEA运行要求不兼容
- plugin.xml缺少Java模块依赖声明
- IntelliJ Gradle插件版本存在依赖解析bug
具体修改方案
1. 修改build.gradle配置
plugins { // 升级IntelliJ Gradle插件到适配2021.2的稳定版本 id 'org.jetbrains.intellij' version '1.10.1' id "org.jetbrains.kotlin.jvm" version '1.5.21' } group 'org.example' version '1.0-SNAPSHOT' repositories { mavenCentral() } // 2021.2版本IDEA最低要求JDK 11,替换原有的1.8配置 sourceCompatibility = 11 targetCompatibility = 11 dependencies { implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.5.21' testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.2' testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.2' } intellij { version '2021.2' plugins = ['java','Kotlin'] } patchPluginXml { changeNotes.set( """ Add change notes here.<br> <em>most HTML tags may be used</em> """ ) } test { useJUnitPlatform() }
2. 修改plugin.xml配置
在依赖节点中添加Java模块依赖声明:
<idea-plugin> <id>org.example.TestPlugin</id> <name>Plugin display name here</name> <vendor email="support@yourcompany.com" url="http://www.yourcompany.com">YourCompany</vendor> <description><![CDATA[ Enter short description for your plugin here.<br> <em>most HTML tags may be used</em> ]]></description> <depends>com.intellij.modules.platform</depends> <depends>org.jetbrains.kotlin</depends> <!-- 新增Java模块依赖,PsiElement属于该模块提供的类 --> <depends>com.intellij.java</depends> <extensions defaultExtensionNs="com.intellij"> <!-- Add your extensions here --> </extensions> <actions> <!-- Add your actions here --> <action id="TestAction" class="org.example.TestAction" text="TestAction" description="TestAction"> <add-to-group group-id="GenerateGroup" anchor="last"/> </action> </actions> </idea-plugin>
3. 生效配置操作
- 执行Gradle的
clean任务后,重新加载所有Gradle项目 - 清除IDE缓存并重启:依次点击File → Invalidate Caches,勾选清除文件系统缓存和本地历史选项后重启IDE即可
内容的提问来源于stack exchange,提问作者ZSpirytus
相关产品推荐
相关产品推荐

