3
<target name="compile" depends="init" description="Compile the source.">
    <javac srcdir="${src}" classpathref="classpath" destdir="${build.bin}" compiler="modern" debug="true" debuglevel="lines,vars,source" includeantruntime="false" source="17" target="17" />
</target>

Eclipse won't build cause my switch contains preview code. How can I enable preview and allow compilation using ANT (build.xml)?

error: patterns in switch statements are a preview feature and are disabled by default.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Clean code
  • 53
  • 5

1 Answers1

4

You can use the Ant <compilerarg> element, which can be nested inside the <javac> element.

Specifically, you need the javac --enable-preview argument.

Example:

<target name="compile" depends="init" description="Compile the source.">
    <javac srcdir="${src}" classpathref="classpath" destdir="${build.bin}" compiler="modern" debug="true" debuglevel="lines,vars,source" includeantruntime="false" source="17" target="17">
        <compilerarg value="--enable-preview" />
    </javac>
</target>

More information and examples for compilerarg can be found here: Ant: passing compilerarg into javac

andrewJames
  • 19,570
  • 8
  • 19
  • 51