【发布时间】:2020-01-21 05:02:12
【问题描述】:
我有一个使用 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>
当我想执行插件时,我在 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'
如何在插件执行中启用预览功能?
【问题讨论】:
-
简单的回答你不能......因为插件是在使用给定 JDK 的给定构建的上下文中执行的......我不知道你为什么使用 JDK 的预览功能在插件中?从我的角度来看没有意义...除此之外,这意味着您不能通过使用已实现的插件来使用早期 JDK 版本运行您的构建...?
-
只是想开始使用新的 switch 语句;如果无法在插件执行时启用预览功能,我将不使用它们!谢谢!
标签: java maven maven-plugin