无法在Intellij idea中使用gradle kotlin DSL构建Kotlin文件

gcmastyq  于 2023-05-18  发布在  IntelliJ IDEA
关注(0)|答案(2)|浏览(376)

我试图在IntelliJ idea中使用gradle kotlin DSL作为构建系统来设置一个Kotlin项目,但在尝试运行buil.gradle.kts文件时出现以下错误。我尝试了不同的Kotlin编译器版本,但没有运气。

warning: default scripting plugin is disabled: The provided plugin org.jetbrains.kotlin.scripting.compiler.plugin.ScriptingCompilerConfigurationComponentRegistrar is not compatible with this version of compiler
error: unable to evaluate script, no scripting plugin loaded

IntelliJ版本:

Gradle版本:6.3
build.gradle.kts

plugins {
    id("org.jetbrains.kotlin.jvm") version "1.3.70"

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

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

dependencies {
    // Align versions of all Kotlin components
    implementation(platform("org.jetbrains.kotlin:kotlin-bom"))

    // 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 = "Music.AppKt"
}
h43kikqp

h43kikqp1#

在IDEA中构建Gradle项目的正确方法是执行“主菜单|建立|Build project”(如果您的构建已在IDEA设置中委托给Gradle),或在Gradle工具窗口中执行以下构建任务之一:http://jetbrains.com/help/idea/work-with-gradle-tasks.html
然而,您描述的行为可以被认为是一个可用性问题,我创建了一个问题https://youtrack.jetbrains.com/issue/KT-37814,请遵循它的更新。

xxls0lw8

xxls0lw82#

添加一个对某些情况也有效的答案。修改build.gradle后,查看gradle文件时不要按三角形的run按钮。移动到其中一个Kotlin/java文件并从那里运行

相关问题