How to set kotlinOptions to --enable-preview in Gradle
Hello,
I want to use OpenJDK19 with preview features enabled in a IntelliJ project using Kotlin and Gradle. It works for Kotlin. In an IntelliJ project without Gradle I can make use of those new features in JDK19 that are only available when -enable-preview is specified as a VM option.
However, it does not work when building the Kotlin project with Gradle using JDK19 as well, although I have upgraded to Gradle 7.5.1 that supports JDK19. I get this error message:
Unsupported Java.
Your build is currently configured to use Java 19 and Gradle 7.5.1.
Question is now how to pass --enable-preview to Gradle in a Kotlin project. I have tried this, but it does not work:
tasks.withType<KotlinCompile> {
kotlinOptions.freeCompilerArgs += "--enable-preview"
kotlinOptions.jvmTarget = "19"
}
Gradle complains about it: Invalid argument: --enable-preview
I simply cannot find the kotlinOptions-Parameter with which I can start Gradle with VM option --enable-preview.
请先登录再写评论。
Hello,
Is it possible to provide sample project for investigation? Kotlin doesn't have "--enable-preview" option. It's possible to pass them to JVM:
```
tasks.withType(JavaCompile)
{ options.compilerArgs += "--enable-preview" }
tasks.withType(Test)
{ jvmArgs += "--enable-preview" }
tasks.withType(JavaExec)
{ jvmArgs += "--enable-preview" }
```
Hi Yaroslav,
I tried with your settings, but it also didn't work with a plain Java and Gradle project. Anyhow, I think I was misled, because Gradle 7.5.1 supports JDK18 and apparently not yet JDK19, see https://docs.gradle.org/7.5.1/release-notes.html
Oliver,
Seems JDK 19 is under development: https://github.com/gradle/gradle/issues/20372