IntelliJ complains with the following exception when I try to make my project.
Error:scalac: 'jvm-1.8' is not a valid choice for '-target'
Error:scalac: bad option: '-target:jvm-1.8'
But a 'gradlew clean install' works just fine.
The project setup is:
gradle version 2.3
scala 2.10 and java
3 of the 4 modules use java 1.7 (source and target compatibility), the 4th module has source and target compatibility 1.8 and is causing the problem.
Any ideas how I can avoid the error? (moving to java 7 is not an option, upgrading scala is)
In Intellij IDEA (15 CE) add this scalac compiler option:
Build, Execution, Deployment -> Compiler -> Scala Compiler -> Default
Additional compiler options: -target:jvm-1.7
(was empty).
There were also profiles Gradle 1, ... with -target:jvm-1.8
, so I changed them also to -target:jvm-1.7
.
I'm using Scala 2.10, JVM 1.8, source compatibility 1.7. It helped in my case.
I got the same error message using IntelliJ 2017.2.5 w/ JRE 1.8.0, scala 2.10.5 and gradle 3.3. I solved my problem by checking the "Delegate IDE build/run actions to gradle" checkbox in IntelliJ's IDE located at
Settings>Build,Execution,Deployment>Build Tools>Gradle>Runner
Details can be found here: https://docs.gradle.org/4.2.1/userguide/scala_plugin.html#ideaTargetVersion and https://www.jetbrains.com/help/idea/gradle.html
Of note, I was able to build my gradle project outside of IntelliJ (i.e. cmd line) and only received this error on attempting to build using the IntelliJ IDE.
Gradle by default use the ant task to build Scala code, and https://issues.scala-lang.org/browse/SI-8966 shows that jvm 1.8 was not added as a supported target until Scala 2.11.5.
You can try using the Zinc based compiler with by adding the following the gradle build file.
tasks.withType(ScalaCompile) {
scalaCompileOptions.useAnt = false
}
You may also need to add the zinc compiler to your dependency list.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With