Java – record is a preview feature and disabled by default. Use –enable-preview to enable [Solution]

To enable preview feature you must define –enable-preview in pom.xml. I’am using java 14

In pom.xml, specify your java compiler version

<properties>
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  <maven.compiler.source>14</maven.compiler.source>
  <maven.compiler.target>14</maven.compiler.target>
</properties>

Next in pom.xml, Edit like below to add compiler arguments (–enable-preview)

<plugin>
  <artifactId>maven-compiler-plugin</artifactId>
  <version>3.8.0</version>
  <configuration>
    <release>14</release><!--Java Version-->
    <compilerArgs>
      <arg>--enable-preview</arg>
    </compilerArgs>
  </configuration>
</plugin>
<plugin>
  <artifactId>maven-surefire-plugin</artifactId>
  <version>2.22.1</version>
  <configuration>
    <argLine>--enable-preview</argLine>
  </configuration> 
</plugin>

Now execute the below maven command

mvn clean verify 

Thats it. Hope this helps

Leave a comment

Design a site like this with WordPress.com
Get started