我正在尝试在Kotlin中使用@Serializable
批注。我可以使用Gradle构建项目,但是在IntelliJ中它显示为红色,当我将鼠标悬停在@Serializable
批注上时,会显示一条消息:
kotlinx.serializable compiler plugin is not applied to the module, so this
annotation would not be processed. Make sure you've setup your buildscript
correctly and re-import project.
我的
build.gradle.kts
文件如下所示:plugins {
id("org.jetbrains.kotlin.jvm").version("1.3.50")
id("org.jetbrains.kotlin.plugin.serialization") version "1.3.50"
idea
}
repositories {
jcenter()
}
dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation(group = "com.charleskorn.kaml", name = "kaml", version = "0.12.0")
testImplementation("org.jetbrains.kotlin:kotlin-test")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit")
}
我安装了最新版本的Kotlin插件(1.3.50)。
最佳答案
所以我开始工作了。问题是我正在使用idea
插件生成IntelliJ项目。相反,当我通过打开build.gradle.kts
文件导入项目时,一切正常。
我之所以没有以这种方式导入它的原因是因为我禁用了Gradle支持,所以当我打开build.gradle.kts
文件时,它没有导入项目,而是在编辑器中打开了它。如果遇到这种情况,请点击cmd
+ shift
+ a
并搜索Gradle
,然后将其切换为On
。重新启动IntelliJ之后,您应该能够从build.gradle.kts
文件导入项目,并且一切顺利。
关于intellij-idea - Kotlin @Serializable注释在IntelliJ中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57701850/