Enable preview feature in Java
Solve preview feature disabled by default. use --enable-preview to enable in Intellij gradle
I upgraded to JDK 21, tried to use the String templates feature which is a preview feature and got hit with the error in IntelliJ: preview feature disabled by default

Meanwhile, I had set the Project language level to 21 (preview) as shown here

Resolution Steps§
To resolve this, let's first confirm that this file can be compiled outside of the Integrated Developer Environment.
The complete code.
Compile command§
output

Run command§
output

It works! we confirmed that we can compile and execute String templates preview feature, we proceed to attempt a fix in the IDE.
The same compile and execute steps need to be run even in the IDE
As gradle doesn't support preview features explicitly, we'll have to add it manually. Add the following to your build.gradle file to pass the argument to the compile task
To enable preview in test task, add the following
Does it work?§
Gradle is fine.
we run ./gradlew clean build and it succeeds

Add VM Option to Intellij§

Select the modify option

Add the VM Option


And that's it !!! Project compiles starts up fine and runs.
You can drop suggestions if you find other ways.
Member discussion