无法在Intellij IDEA中使用Gradle Kotlin DSL构建Kotlin文件

9
我尝试在IntelliJ idea中使用gradle kotlin DSL作为构建系统来设置一个kotlin项目,但是当我尝试运行build.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"
}

请提供您的主Gradle构建文件内容,您正在使用的Intellij版本以及项目的Gradle版本。 - Cisco
1
“当尝试运行build.gradle.kts文件”是什么意思?您能更好地描述一下在IJ中正在做什么吗? - Louis Jacomet
我已经复现了这个问题,如果当前脚本(主菜单 | 运行 | 运行 build.gradle.kts)显式地执行“运行”操作。但这是错误的做法。如果你想构建项目,应该在 IDEA 设置中将构建委托给 Gradle,并在 Gradle 工具窗口中执行其中一个构建任务:https://www.jetbrains.com/help/idea/work-with-gradle-tasks.html - Alexey Belkov
2个回答

12

1
感谢您的回答,我在这个问题上浪费了很多时间。https://dev59.com/gbroa4cB1Zd3GeqPdBOc 。我必须说,我的经验是,如果我在使用某个工具的1小时内遇到错误,那么这个工具很可能是垃圾。这让我对使用Intellij / Kotlin感到不满。也许我会选择Python。 - MWB

1

添加一个答案,适用于某些情况。在修改了build.gradle文件后,不要在查看gradle文件时按三角形运行按钮。移动到其中一个kotlin/java文件并从那里运行。


你的回答可以通过提供额外的支持信息来改进。请进行[编辑]以添加更多细节,例如引用或文档,以便他人可以确认你的答案是否正确。你可以在帮助中心找到有关如何编写好答案的更多信息。 - Community

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接