如何使用 <compilerarg value=""> 通过 <javac> Ant 任务将命令行选项传递给 java 编译器?

How to pass command line options to the java compiler through the <javac> Ant task using <compilerarg value="">?

要使用预览功能编译代码,javac 需要选项 --enable-preview--release

如果我使用 line 属性将这些选项传递给 <javac> Ant 任务 (Ant 1.10.5),如下所示,编译成功。

<compilerarg line="--enable-preview --release 15"/>

但是如果我使用 value 属性将它们作为单独的参数传递,如下所示,Ant 会抛出 error: invalid flag: --release 15.

<compilerarg value="--enable-preview"/>
<compilerarg value="--release 15"/>

由于 Ant 手册 says“强烈建议尽可能避免使用行版本”,我想知道如何使代码也与 value 属性一起工作.有什么诀窍?

需要三个参数,例如:

<compilerarg value="--enable-preview"/>
<compilerarg value="--release"/>
<compilerarg value="15"/>

...否则,如您所见,“--release 15”被视为带有嵌入式 space.

的单个参数