HoTicE
HoTicE

Reputation: 573

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

Upvotes: 3

Views: 2472

Answers (3)

Newt0n
Newt0n

Reputation: 73

I stumbled over this issue when having the same problem with Java 11. The reconfiguration comment of Roland Ewald solved the problem. It is important to mention, that this reconfiguration has to be made for all modules of the project (at least for me this was necessary) as well as that IntelliJ sometimes hides parts of the Additional compiler options, so be sure to click on expand even if they seem empty or correct.

Upvotes: 0

Roland Ewald
Roland Ewald

Reputation: 4614

The same issue can happen with mixed multi-module gradle projects that use java 11 and scala 2.12.10.

In that case, it may help to reconfigure IntelliJ (2019.2) via

Settings > Build, Execution, Deployment > Scala Compiler

by removing the targets defined in Additional compiler options for the affected scala modules.

Upvotes: 2

Madhawa Gunasekara
Madhawa Gunasekara

Reputation: 408

"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.

Upvotes: 3

Related Questions