在 POM 中使用 --enable-preview 执行 Maven 插件

Gio*_*ato 5 java maven-plugin maven

我有一个使用 JDK 12 预览功能的自定义 Maven 插件。我将插件设置--enable-preview编译为编译器 arg,即

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
        <compilerArgs>
            <compilerArg>--enable-preview</compilerArg>
        </compilerArgs>
    </configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)

当我想执行插件时,我在POM中添加这样的插件:

<plugin>
    <groupId>my.group</groupId>
    <artifactId>my-plugin</artifactId>
    <executions>
        <execution>
            <phase>generate-sources</phase>
            <goals>
                <goal>my-goal</goal>
            </goals>
        </execution>
    </executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)

但这失败了:

Preview features are not enabled for MyPluginMojo. Try running with '--enable-preview'
Run Code Online (Sandbox Code Playgroud)

如何在插件执行中启用预览功能?

Ran*_*alt 5

对我来说,我必须将配置文件添加到我的构建目录中:

.mvn/jvm.config
Run Code Online (Sandbox Code Playgroud)

包含:

--enable-preview
Run Code Online (Sandbox Code Playgroud)

这将确保 Maven 将正确的参数传递给 JVM