This article shows you how to enable preview feature in Java.

–enable-preview to enable text blocks:

To enable the preview feature, make sure you are using java 12 or later version. Even if you are using Java 12 or above versions you might get “Use --enable-preview to enable text blocks” error because the text blocks and preview feature are disabled by default. We have to enable them manually.

–enable-preview Intellij:

In intellij goto File->Project Structure-> Project and makesure the below selected items

--enable-preview to enable text blocks

–enable-preview terminal:

# compiling
javac --release 14 --enable-preview  // Enable all preview features of JDK 12

java --enable-preview Demo      // Run with preview features of JDK 14

–enable-preview maven:

Add the below maven plugin in pom.xml to enable-preview


–enable-preview gradle:

For gradle you need to configure the javaCompile task, so that Gradle passes this option to the Java compiler when compiling the java classes. Add the below code in build.gradle file

tasks.withType(JavaCompile).each {
test {


Happy Learning 🙂