我试图让 Kotlin 脚本工作,但 Gradle 和 IntelliJ IDEA 都无法构建项目,因为它们无法找到基本脚本定义中定义的方法。
有关示例项目,请参阅https://github.com/sinoz/sample-kts。add
它包括一个使用基本脚本定义中定义的方法添加两个值的简单脚本和一个引用所述脚本定义的脚本模板文件。
运行 gradle 构建:
~/Documents/Hobby/untitled1$ gradle build
> Task :compileKotlin FAILED
e: /home/sino/Documents/Hobby/untitled1/src/main/kotlin/me/sino/add.kts: (3, 1): Unresolved reference: add
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileKotlin'.
> Compilation error. See log for more details
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 1s
1 actionable task: 1 executed
我正在使用 IntelliJ IDEA 2020.2、Gradle 6.8、Kotlin 1.4.10 和 OpenJDK 11。在我重新安装 Linux 和 Windows 之前,Kotlin 脚本曾经可以正常工作(所以我假设其中涉及一些缓存,允许 Kotlin 脚本继续运行)。
IDEA 也没有像以前那样让我选择应用新的脚本上下文。我不确定如何手动执行此操作,因为我无法找到任何有关它的文档。