在 POM 中使用 --enable-preview 执行 Maven 插件 [英] Execute a Maven plugin with --enable-preview in POM

查看:53
本文介绍了在 POM 中使用 --enable-preview 执行 Maven 插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a custom Maven plugin which makes use of JDK 12 preview features. I compile the plugin setting --enable-preview as compiler arg, i.e.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
        <compilerArgs>
            <compilerArg>--enable-preview</compilerArg>
        </compilerArgs>
    </configuration>
</plugin>

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

When I want to execute the plugin, I add the plugin like this in the 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>

但这失败了:

Preview features are not enabled for MyPluginMojo. Try running with '--enable-preview'

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

How can I enable preview features in a plugin execution?

推荐答案

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

For me, I had to add a config file to my build directory at:

.mvn/jvm.config

包含:

--enable-preview

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

This will make sure that Maven passes the correct parameters to JVM

这篇关于在 POM 中使用 --enable-preview 执行 Maven 插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆