Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error:scalac: 'jvm-1.9' is not a valid choice for '-target'

Created a new clean Scala project using Gradle.

This is the only dependency:

compile "org.scala-lang:scala-library:2.12.4"

When building on the command line ./gradlew build works perfectly fine. However, when using IntelliJ it gives me this warning:

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

I have both the JDK with java 8 and 9 installed, but I'm currently using JDK 1.8. But I'm not sure if that's related.

like image 436
Ole-M Avatar asked Mar 09 '18 14:03

Ole-M


1 Answers

In Scala 2.12, the Scala compiler always compiles to Java 8 compatible bytecode.

You can find more info below:

  1. Compiling and testing Scala 2.12
  2. Scala-lang: JAVA 8 BYTECODE FOR LAMBDAS

Add the following lines to your build.gradle:

compileScala.targetCompatibility = 1.8
ScalaCompileOptions.metaClass.useAnt = false
like image 171
Dmytro Melnychuk Avatar answered Oct 22 '22 14:10

Dmytro Melnychuk