Search code examples
scalaintellij-ideabuild.gradlejava-10

Scala not builds on Java 10


while building through Intellij Idea, I got the following message:

Error:scalac: 'jvm-1.10' is not a valid choice for '-target' Error:scalac: bad option: '-target:jvm-1.10'

later, after a Java upgrade

Build, Execution, Deployment -> Build Tools -> Gradle -> Gradle JVM: 1.8 Build, Execution, Deployment -> Complier -> Scala Complier -> Scala Compile Server -> JDK: 1.8

in build.gradle

compileScala.targetCompatibility = 1.8
ScalaCompileOptions.metaClass.useAnt = false

Nothing helps!

upd: this helps: in build.gradle

tasks.withType(ScalaCompile) {
    scalaCompileOptions.useAnt = false
}

not needed:

compileScala.targetCompatibility = 1.8 
ScalaCompileOptions.metaClass.useAnt = false

Solution

  • "Error:scalac: 'jvm-1.10' is not a valid choice for '-target' Error:scalac: bad option: '-target:jvm-1.10'"

    • In the JDK compatibility notes as mentioned below, it also indicates that the Java 10 is not fully supporting Scala 2.12.6 JDK 9 & 10 compatibility notes
    • As you were saying you build this through IntelliJ IDEA, I suspect you haven't configure your java version (Java 10) or scala version (2.12.6) inside running configuration project settings.

    • And also please try out building/compile your application through
      commandline in order to check whether you are getting the same error with that (Otherwise this is just bad configuration in IDEA tht you
      need to change)

    JDK 9 & 10 compatibility notes (Mentioned in Scala Docs)

    JDK 9 & 10 compatibility notes As of Scala 2.12.6 and 2.11.12, JDK 9 & 10 support is incomplete. Notably, scalac will not enforce the restrictions of the Java Platform Module System, which means that code that typechecks may incur linkage errors at runtime.

    JDK 9 & 10 support requires minimum sbt version 1.1.0, or 0.13.17 in the 0.13.x series.

    For more information on JDK 9 & 10 compatibility, watch the “Support JDK 9” issue on GitHub.