Reputation: 2243
The problem
> Task :compileScala FAILED
'jvm-1.11' is not a valid choice for '-target'
bad option: '-target:jvm-1.11'
After struggling for hours, I have no ideas left on how to resolve this.
% ./gradlew --version
------------------------------------------------------------
Gradle 7.5.1
------------------------------------------------------------
Build time: 2022-08-05 21:17:56 UTC
Revision: d1daa0cbf1a0103000b71484e1dbfe096e095918
Kotlin: 1.6.21
Groovy: 3.0.10
Ant: Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM: 11.0.13 (Azul Systems, Inc. 11.0.13+8-LTS)
OS: Mac OS X 12.6.1 aarch64
I can see this basic problem with the Gradle Scala Plugin covered in many places over the years, even in StackOverflow, but none of the solutions seem to work in this case.
tasks.withType(ScalaCompile) {
scalaCompileOptions.with {
sourceCompatibility = "1.8"
targetCompatibility = '1.8'
}
}
Proposed in other places does not seem to work with this version of Gradle.
dependencies {
. . .
implementation 'org.scala-lang:scala-library:2.10.4'
. . .
}
Changing the Java version breaks other things in the project.
java {
toolchain {
languageVersion = JavaLanguageVersion.of(11)
}
}
Upvotes: 3
Views: 647
Reputation: 127971
Note that sourceCompatibility
/targetCompatibility
have no effect on Scala compilation task. You should avoid any options with these names, actually.
The error that you see is basically a known bug which won't be fixed.
The workaround is to specify the -target
option explicitly, in the format which Scala compiler of your particular version does understand:
tasks.withType(ScalaCompile).configureEach {
scalaCompileOptions.additionalParameters = ['-target:jvm-1.8']
}
Upvotes: 4