我想在我的 libGdx 项目中编译仅适用于桌面的 .scala 文件,但出现此错误
Executing task 'DesktopLauncher.main()'...
Executing tasks: [DesktopLauncher.main()]
Task :core:compileJava UP-TO-DATE Task :core:processResources NO-SOURCE Task :core:classes UP-TO-DATE Task :core:jar UP-TO-DATE
Task :desktop:compileJava FAILED warning: [options] bootstrap class path not set in conjunction with -source 1.6 C:\Users\cpepi001\Desktop\myGdxGame\desktop\src\com\mygdx\game\desktop\DesktopLauncher.java:11: error: cannot find symbol new HelloScala(); ^ symbol: class HelloScala location: class DesktopLauncher 1 error 1 warning
FAILURE: Build failed with an exception.
What went wrong: Execution failed for task ':desktop:compileJava'. Compilation failed; see the compiler error output for 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
Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0. Use '--warning-mode all' to show the individual deprecation warnings. See https://docs.gradle.org/5.4.1/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 0s 3 actionable tasks: 1 executed, 2 up-to-date 2:10:42 PM: Task execution finished 'DesktopLauncher.main()'.
重现步骤:
- 创建一个新的 LibGDX 项目
- 右键单击桌面模块 -> 添加框架支持 -> Scala (v2.10.4)
- 在桌面模块中创建一个新的 .scala 文件
- 在 DesktopLauncher.java 中实例化该类(即
new HelloScala);
)
我也尝试this guide没有成功
最佳答案
我设法找到了解决方案
build.gradle(项目
<project_name>
)- 将 Scala 插件添加到
project(":core")
部分:apply plugin: "scala"
- 依赖项中包含 scala 库:
implementation "org.scala-lang:scala-library:$scalaLibraryVersion"
- 将 Scala 插件添加到
build.gradle(模块:桌面)
- 更改 sourceSets.main。
java
.srcDirs = [“src/”] 到 sourceSets.main。scala
.srcDirs = [“src/”]
- 更改 sourceSets.main。
关于java - libGdx 和 Gradle 的 Scala 实例化错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58779197/