为 gretty 插件启用预览功能

enable preview features for gretty plugin

我正在尝试 运行 Spring MVC 应用程序使用 Gradle 的 gretty 插件(JVM 版本是 14) 要部署应用程序,我使用 tomcatRun 任务(tomcat 版本为 8.5.49)。

如果我使用某些预览功能(例如 java.lang.String#formatted method),我必须将 enable-preview 标记添加到 compileJava 任务:

compileJava {
    options.compilerArgs += '--enable-preview'
}

但是,如果 build.gradle 包含此类更改,则会出错并且日志中会出现以下消息:

INFO: No Spring WebApplicationInitializer types detected on classpath 因此,所有应用端点都不可用。

如果使用 jettyRun 任务,则会抛出以下异常:

17:14:38 WARN  Failed startup of context o.a.g.JettyWebAppContext@2715644a
java.lang.UnsupportedClassVersionError: Preview features are not enabled for com/config/ApplicationDispatcherServletInitializer (class file version 58.65535). Try running with '--enable-preview'

是否可以使用 gretty 插件的预览功能?

通过将 --enable-preview 添加到 gretty 配置中的 JVM 参数列表来解决:

build.gradle
gretty {
    jvmArgs = ['--enable-preview']
}

检查 Jetty(9.4.24.v20191120) 和 Tomcat(8.5.49)