首页 > 解决方案 > 预期 java.lang.string,找到 kotlin.string。intellij中的kotlin gradle错误

问题描述

kotlin application我通过gradle init --dsl kotlin-> 将项目加载到 intellij生成一个骨架,我收到以下错误。附上截图。

Type mismatch : inferred type is kotlin.String but java.lang.String was expected.

我尝试了使缓存/重启无效的各种步骤。删除 .gradle、.idea、~/.gradle 等。刷新 gradle 项目,停止 gradle 守护进程。刷新 intellij 项目(删除 ~/.intellijIDea../system 目录)。然而,没有人有帮助。请告诉我我还能做什么?

正如我所说,我通过gradle init --dsl kotlin. gradle 版本 5.2.1,kotlin 插件版本 1.3.20。都是最新的。intellij idea 为 2018.3 版本。对于初学者,build.gradle.kts如下所示:

plugins {
    // Apply the Kotlin JVM plugin to add support for Kotlin on the JVM.
    id("org.jetbrains.kotlin.jvm").version("1.3.20")

    // Apply the application plugin to add support for building a CLI application.
    application
}

repositories {
    // Use jcenter for resolving your dependencies.
    // You can declare any Maven/Ivy/file repository here.
    jcenter()
}

dependencies {
    // Use the Kotlin JDK 8 standard library.
    implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")

    // Use the Kotlin test library.
    testImplementation("org.jetbrains.kotlin:kotlin-test")

    // Use the Kotlin JUnit integration.
    testImplementation("org.jetbrains.kotlin:kotlin-test-junit")
}

application {
    // Define the main class for the application.
    mainClassName = "info.XXX.YYY"
}

在此处输入图像描述

标签: gradleintellij-ideagradle-kotlin-dsl

解决方案


在堆栈溢出时,我登陆了一个链接,它通知使用 oracle jdk 而不是 openjdk。安装了 oracle jdk -> 使缓存/重启无效,为我做了。


推荐阅读