Search code examples
javascalagradleintellij-idealibgdx

Scala instantiation error with libGdx and Gradle


I want to compile .scala files in my libGdx project only for Desktop but this error shows up

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()'.

Steps to reproduce:

  1. Create a new LibGDX project
  2. Right click to desktop module -> Add framework support -> Scala (v2.10.4)
  3. Make a new .scala file inside the desktop module
  4. Inside DesktopLauncher.java instantiate the class (i.e. new HelloScala);)

Also I try this guide with no success


Solution

  • I managed to find a solution

    1. build.gradle(Project <project_name>)

      • Add the Scala plugin to the project(":core") section: apply plugin: "scala"
      • In the dependencies include the scala library: implementation "org.scala-lang:scala-library:$scalaLibraryVersion"
    2. build.gradle(Module: desktop)

      • Change sourceSets.main.java.srcDirs = [ "src/" ] to sourceSets.main.scala.srcDirs = [ "src/" ]