简体   繁体   中英

Scala build error on Java 11 using intellijidea

When I build my project from IntellijIdea I get the following errors

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

I am using gradle to build my project. My project is using java 11 and scala 2.12.8.

Can someone help me resolve this error?

Scala 2.12 doesn't support JVM 11 as a target. You need to add this to your gradle build file:

tasks.withType<ScalaCompile> {
    targetCompatibility = "1.8"
}

As for Scala 2.13, the fix for this issue is:

tasks.withType<ScalaCompile>() {
    targetCompatibility = ""
    scalaCompileOptions.additionalParameters = listOf("-target:11")
}

In my case, I simply had Scala misconfigured after Idea update.

Scala 12 can in fact be compatible with Java 11. It's better to check compatibility table .

I had to remove my previous Scala library from Project Structure and re-added it as described in this answer.

This is due to a bug in IntelliJ (or IntelliJ's Scala plugin):

https://youtrack.jetbrains.com/issue/SCL-18813

I have posted there a workaround, which was inspired by IvanoBulo's answer above.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM