问题描述
我正在尝试让 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 也没有让我可以像以前那样应用新的脚本上下文。我不确定如何手动执行此操作,因为我找不到任何相关文档。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)