-
Notifications
You must be signed in to change notification settings - Fork 41.4k
Description
Environment
- Spring Boot 3.1.0
- JDK 17
- GraalVM 22.3.1
- Gradle 8.1.1
- Gradle GraalVM native image plugin 0.9.22
- Groovy 4.0.12
Problem
Excluding an auto-configuration class, such as GroovyTemplateAutoConfiguration
via application properties, causes property binding to fail when building and launching GraalVM native images. The basic setup should be as follows (I can certainly put together a reproducer, if it helps to clarify the scenario):
- In
application.yml
file, define:
spring:
autoconfigure:
exclude: org.springframework.boot.autoconfigure.groovy.template.GroovyTemplateAutoConfiguration
- Ensure the application contains the dependency
groovy-templates-4.0.12.jar
to satisfy the conditions required byGroovyTemplateAutoConfiguration
, and then:
./gradlew nativeCompile
Launch the native image to see:
2023-05-31 08:04:47 WARN o.s.b.w.s.c.ServletWebServerApplicationContext -
Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'welcomePageHandlerMapping': Instantiation of supplied bean failed
2023-05-31 08:04:47 ERROR o.s.b.d.LoggingFailureAnalysisReporter -
***************************
APPLICATION FAILED TO START
***************************
Description:
Failed to bind properties under 'spring.groovy.template' to
org.springframework.boot.autoconfigure.groovy.template.GroovyTemplateAvailabilityProvider$GroovyTemplateAvailabilityProperties:
Reason: java.lang.NoSuchMethodException:
org.springframework.boot.autoconfigure.groovy.template.GroovyTemplateAvailabilityProvider$GroovyTemplateAvailabilityProperties.<init>()
Action:
Update your application's configuration
Analysis
-
GroovyTemplateAutoConfiguration
is tagged with@ImportRuntimeHints({GroovyTemplateRuntimeHints.class})
. Excluding the class will also deactivate the runtime hint registration process. -
This is a bit of a tricky scenario where in the general sense, the app wants to use and have access to the functionality offered by a dependency, i.e.
groovy-templates-4.0.12.jar
, and yet does not need or want to activate the Spring Boot auto-configuration that detects that library. -
The following construct does not exclude the auto-configuration class, when attached to the application's entrypoint:
@SpringBootApplication(exclude = {
GroovyTemplateAutoConfiguration.class
}, proxyBeanMethods = false)
After including the above, the AOT generated sources continue to include bean definitions found and processed by GroovyTemplateAutoConfiguration
.
- Removing the exclusion rules altogether and starting clean with just the noted dependency causes other issues when building and launching GraalVM native images, i.e.:
Error creating bean with name 'groovyMarkupConfigurer': No signature of method: org.codehaus.groovy.control.customizers.ASTTransformationCustomizer$_setAnnotationParameters_closure1.doCall() is applicable for argument types: (SimpleImmutableEntry) values: [extensions=groovy.text.markup.MarkupTemplateTypeCheckingExtension]
Possible solutions: findAll(), findAll(), isCase(java.lang.Object), isCase(java.lang.Object)
...and many other similar errors, all groovy-related. There is no other way to skip the generation of the groovyMarkupConfigurer
bean, other than to perhaps reconstruct it again, mute it and allow spring-bean-overriding.
If you'd like to see a reproducer, please let me know.