not specifically kotlin related, how can I set sou...
# gradle
r
not specifically kotlin related, how can I set source/targetCompatibility to a lower version (in my case 1.8) when I am using
kotlin { jvmToolchain(11) }
I basically want to release my library with source/target compatibility for 1.8 but still be sure that the project compiles with 11. I also have tests which only make sense running under java 11, so switching to jvmToolChain(1.8) is not an option. Or I would need to have separate tasks which run the jdk 11 specific tests which seems neither a good option compared to the old way of using source/targetCompatibility where it just worked. Ideas?
v
For Java you can set a toolchain and still use
*Compatibility
like expected. Maybe it works for Kotlin too.
For tests, you can use stuff like
Copy code
tasks.withType<Test>().configureEach {
    javaLauncher.set(javaToolchains.launcherFor {
        languageVersion.set(JavaLanguageVersion.of(11))
    })
}
r
ah... it's only intellij which complains not gradle
ah no... must have been a glitch, now I get again:
Copy code
Task :compileJava FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileJava'.
> Error while evaluating property 'sourceCompatibility' of task ':compileJava'
   > The new Java toolchain feature cannot be used at the project level in combination with source and/or target compatibility
m
I do this:
Copy code
project.tasks.withType(JavaCompile::class.java).configureEach {
    // Ensure "org.gradle.jvm.version" is set to "8" in Gradle metadata of jvm-only modules.
    options.release.set(8)
  }
r
that works 👍