【发布时间】:2019-08-15 16:20:15
【问题描述】:
我正在尝试编译一个项目,其中包含一些用 groovy 编写的测试。
该项目有用于 Java 12 的 --enable-preview。
我正在使用 gmavenplus-plugin 来做到这一点:
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.6.3</version>
<configuration>
<targetBytecode>${java.version}</targetBytecode>
<testSources>
<testSource>
<directory>${testSourceDirectory}</directory>
<includes>
<include>**/*.groovy</include>
</includes>
</testSource>
</testSources>
</configuration>
<executions>
<execution>
<goals>
<goal>compileTests</goal>
</goals>
</execution>
</executions>
</plugin>
我有 --enable-preview 用于 maven 编译器和 surefire/failsafe(使用 argLine)。如果我禁用 groovy 插件(和测试),一切正常。
但是当我启用它时,它会失败:
Failed to execute goal org.codehaus.gmavenplus:gmavenplus-plugin:1.6.3:compileTests (default) on project apikey-manager-api: Error occurred while calling a method on a Groovy class from classpath.: InvocationTargetException: Preview features are not enabled for com/acme/config/EndToEndTest (class file version 56.65535). Try running with '--enable-preview' -> [Help 1]
我没有看到任何可以传递给此插件以启用预览功能的选项。它使用javac吗?或者这样的选项应该在 groovyc 中吗?
【问题讨论】:
-
看起来编译正在运行,但是在没有设置 --enable-preview 的情况下运行测试。如果您可以使用
javap -v <class>从测试中检出已编译的 .class 文件,您可以检查次要类文件版本是否非零,以验证它是使用 --enable-preview 编译的。 -
@JornVernee 不幸的是,groovy 编译不起作用,它失败了,因为它看到 EndToEnd.class 是一个用 --enable-preview 编译的 java 类,结果 groovyc 失败了。
-
哦,我明白了,所以 groovyc 正在尝试加载使用 --enable-preview 编译的这个类,然后它失败了,因为 groovyc 没有在设置了 --enable-preview 的 JVM 中运行。也许setting the
JAVA_OPTS环境变量“--enable-preview”会起作用? (这可以使用 groovy 命令行进行隔离)
标签: java groovy java-12 gmavenplus