DZone

Java introduced preview features in the language starting in Java 12. These features can be tried out by developers, but are still subject to change and can even be removed in the next release. By default, the preview features are not enabled when we want to compile and run our Java code. We must explicitly specify that we want to use the preview feature to the Java compiler and Java runtime using the command-line argument --enable-preview. In Gradle, we can customize our build file to enable preview features. We must customize tasks of type JavaCompile and pass --enable-preview to the compiler arguments. Also tasks of type Test and JavaExec must be customized where we need to add the JVM argument --enable-preview.

In the following Gradle build script written in Kotlin, we have a Java project written with Java 15 where we reconfigure the tasks to enable preview features:

Source: DZone