Intellij idea Kotlin@Serializable注释在IntelliJ中不起作用
我试图在Kotlin中使用Intellij idea Kotlin@Serializable注释在IntelliJ中不起作用,intellij-idea,kotlin,Intellij Idea,Kotlin,我试图在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 cor
@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
文件导入项目,您应该可以开始了。您需要添加:
plugins {
application
kotlin("jvm") version "1.4.21"
kotlin("plugin.serialization") version "1.4.21"
}
这由JetBrains在此处指定,链接到gradle:
刚刚检查了配置-一切正常。尝试刷新Gradle(在IDE中),或/或重新启动IDE.Hmm,您有哪个版本的IntelliJ?具体来说,这段代码是红色的:
DataClassWithSerializableAnnotation.serializer()
另外,如何将项目“导入”到IntelliJ中?我运行/gradlew idea
,然后打开生成的project.IntelliJ idea ultimate 2019.2 EAP。我刚刚创建了一个新项目,并将build.gradle替换为*.ktsHeya@MaxFarsikov,我成功了。诀窍是通过打开build.gradle.kts
文件导入项目,而不是运行/gradlew idea
。谢谢你的帮助!