enable preview features for gretty plugin

181 Views Asked by At

I'm trying to run Spring MVC app using gretty plugin for Gradle (JVM version is 14) To deploy app I use tomcatRun task (tomcat version is 8.5.49).

If i use some preview feature (e.g. java.lang.String#formatted method) I have to add enable-preview flag to compileJava task:

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

However, if build.gradle contains such changes, something goes wrong and the following message appears in logs:

INFO: No Spring WebApplicationInitializer types detected on classpath As a result all app endpoints aren't available.

In case of using jettyRun task the following exception is thrown:

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'

Is it possible to use preview features with gretty plugin?

1

There are 1 best solutions below

0
Sergei On BEST ANSWER

Solved by adding --enable-preview to the list of JVM arguments in gretty configuration:

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

Checked on both Jetty(9.4.24.v20191120) and Tomcat(8.5.49)