IntelliJ插件Gradle更新问题:changeNotes与intellijPlatform配置异常
问题描述
数月前发布过一款IntelliJ插件更新,近期回到项目时无法完成构建。更新Gradle相关配置后,项目能正常构建且插件测试部署成功,但不得不注释原有的changeNotes代码——该功能原本用于在IDE及插件市场展示更新日志,现在提示未定义。推测该功能可能迁移至org.jetbrains.intellij.platform,但尝试配置intellijPlatform时构建失败,出现类定义冲突、要求升级Gradle 8.5或类型转换错误等问题。使用环境为IDEA 2023.3.2、macOS 15.3。
当前build.gradle.kts代码
plugins { id("java") id("org.jetbrains.kotlin.jvm") version "1.9.21" id("org.jetbrains.intellij") version "1.16.1" // id("org.jetbrains.intellij.platform") version "2.0.1" } group = "com.my-domain" version = "1.0.6" // Configure Gradle IntelliJ Plugin // Read more: https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html intellij { version.set("2023.1.5") type.set("IC") // Target IDE Platform plugins.set(listOf(/* Plugin Dependencies */)) // Haven't figured out what dependencies, if any, should go here } repositories { mavenCentral() // intellijPlatform { // Flagged as undefined unless I comment it out // releases() // marketplace() // } } tasks { // Set the JVM compatibility versions withType<JavaCompile> { sourceCompatibility = "17" targetCompatibility = "17" } withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> { kotlinOptions.jvmTarget = "17" } patchPluginXml { sinceBuild.set("231") untilBuild.set("241.*") } signPlugin { certificateChain.set(System.getenv("CERTIFICATE_CHAIN")) privateKey.set(System.getenv("PRIVATE_KEY")) password.set(System.getenv("PRIVATE_KEY_PASSWORD")) } publishPlugin { token.set(System.getenv("PUBLISH_TOKEN")) } } tasks.getByName<org.jetbrains.intellij.tasks.PatchPluginXmlTask>("patchPluginXml") { // Commented out because it doesn't work anymore as is. // changeNotes(""" // <h2>1.0.5</h2> // <ul><li>Blah, blah, blah.</ul> // <h2>1.0.4</h2> // <ul><li>Blah, blah, blah.</ul> // <h2>1.0.3</h2> // <ul><li>Blah, blah, blah.</ul> // <h2>1.0.2</h2> // <ul><li>Blah, blah, blah.</ul> // <h2>1.0.1</h2> // <ul><li>Blah, blah, blah.</ul> // <h2>1.0.0</h2> // <ul><li>First release</li></ul> //""" // ) }
报错信息
Build file '/Users/username/code/my-project/build.gradle.kts' line: 1 An exception occurred applying plugin request [id: 'org.jetbrains.intellij.platform', version: '2.0.1'] > Failed to apply plugin class 'org.jetbrains.intellij.platform.gradle.plugins.project.IntelliJPlatformBasePlugin'. > Failed to cast object task ':printBundledPlugins' of type org.jetbrains.intellij.tasks.PrintBundledPluginsTask_Decorated to target type org.jetbrains.intellij.platform.gradle.tasks.PrintBundledPluginsTask * Try: > Run with --stacktrace option to get the stack trace. > Run with --info or --debug option to get more log output. > Run with --scan to get full insights. > Get more help at https://help.gradle.org. BUILD FAILED in 637ms Configuration cache entry stored.
解决方案
1. 升级Gradle版本
org.jetbrains.intellij.platform 2.0.x版本要求Gradle 8.5及以上,修改项目根目录下gradle/wrapper/gradle-wrapper.properties中的distributionUrl:
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
2. 替换插件并调整配置
移除旧的org.jetbrains.intellij插件,改用新的org.jetbrains.intellij.platform插件,同时调整配置结构:
修改后的完整build.gradle.kts代码:
plugins { id("java") id("org.jetbrains.kotlin.jvm") version "1.9.21" id("org.jetbrains.intellij.platform") version "2.0.1" } group = "com.my-domain" version = "1.0.6" intellijPlatform { ide { version.set("2023.1.5") type.set("IC") // Target IDE Platform } plugins.set(listOf(/* 插件依赖,按需添加 */)) } repositories { mavenCentral() intellijPlatform { releases() marketplace() } } tasks { withType<JavaCompile> { sourceCompatibility = "17" targetCompatibility = "17" } withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> { kotlinOptions.jvmTarget = "17" } patchPluginXml { sinceBuild.set("231") untilBuild.set("241.*") // 恢复changeNotes配置,使用set()方法 changeNotes.set(""" <h2>1.0.5</h2> <ul><li>Blah, blah, blah.</ul> <h2>1.0.4</h2> <ul><li>Blah, blah, blah.</ul> <h2>1.0.3</h2> <ul><li>Blah, blah, blah.</ul> <h2>1.0.2</h2> <ul><li>Blah, blah, blah.</ul> <h2>1.0.1</h2> <ul><li>Blah, blah, blah.</ul> <h2>1.0.0</h2> <ul><li>First release</li></ul> """.trimIndent()) } signPlugin { certificateChain.set(System.getenv("CERTIFICATE_CHAIN")) privateKey.set(System.getenv("PRIVATE_KEY")) password.set(System.getenv("PRIVATE_KEY_PASSWORD")) } publishPlugin { token.set(System.getenv("PUBLISH_TOKEN")) } }
关键说明
- 旧插件
org.jetbrains.intellij和新插件org.jetbrains.intellij.platform不能同时启用,否则会触发类类型转换冲突,必须完全替换。 - 新插件将IDE配置移至
intellijPlatform.ide节点下,结构更清晰。 changeNotes在新插件中通过changeNotes.set()方法赋值,而非旧插件的直接调用方式。- 若原有插件依赖,可在
intellijPlatform.plugins列表中添加对应的插件ID,比如com.intellij.java等。
内容的提问来源于stack exchange,提问作者kshetline
相关产品推荐
相关产品推荐

