问题
IDEA提示: Some Kotlin libraries attached to this project were compiled with a newer Kotlin Compiler and can’t be read. Please update Kotlin plugin.
原因
Kotlin插件版本应该是跟Kotlin语言版本对应的,如果出现标题所示错误,那么应该检查以下内容是否匹配:
- Kotlin插件版本
- Kotlin编译器版本
- 项目中Kotlin插件的相应配置
示例
在IDEA中使用Spring Initializr创建Kotlin项目,结果出现上面的问题,后来发现是项目中Kotlin插件配置中语言和插件版本都是1.6.0,修改与插件版本1.4.21一致后解决。
以下是插件、IDE设置(图中已经有提示模块覆盖了项目设置,这里应该是覆盖了IDE设置)


项目模块中Kotlin插件设置在 build.gradle.kts 文件中:
plugins {
id("org.springframework.boot") version "2.4.13"
id("io.spring.dependency-management") version "1.0.11.RELEASE"
kotlin("jvm") version "1.4.21"
kotlin("plugin.spring") version "1.4.21"
}