spring-bootgrailsgrails-5

java.lang.ClassNotFoundException: org.grails.core.cfg.DeprecatedGrailsConfig


I'm updating a Grails 3.3.16 app to Grails 5.3.2. When I grails run-app I'm getting a strange exception and can't see the source is in my code, and couldn't find a solution online.

Hope someone had a similar issue and can give some light to the source on this error.

UPDATE: I think there is a double issue here: 1. it seems one config I'm using is deprecated, 2. when Grails reports the deprecation, it uses a class that doesn't exists in Grails 5, so I get that error and not the error of the config I need to change. Maybe others can have a better diagnosis. If it's that, there is a bug in Grails 5 besides my config bug.

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'convertersConfigurationInitializer': Lookup method resolution failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [org.grails.web.converters.configuration.ConvertersConfigurationInitializer] from ClassLoader [jdk.internal.loader.ClassLoaders$AppClassLoader@67424e82]
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:289)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineConstructorsFromBeanPostProcessors(AbstractAutowireCapableBeanFactory.java:1302)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1219)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
        at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:955)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583)
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:147)
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:731)
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:408)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:307)
        at grails.boot.GrailsApp.run(GrailsApp.groovy:99)
        at grails.boot.GrailsApp.run(GrailsApp.groovy:485)
        at grails.boot.GrailsApp.run(GrailsApp.groovy:472)
        at grails.boot.GrailsApp$run.call(Unknown Source)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:148)
        at openehr.opt.gui.Application.main(Application.groovy:8)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
Caused by: java.lang.IllegalStateException: Failed to introspect Class [org.grails.web.converters.configuration.ConvertersConfigurationInitializer] from ClassLoader [jdk.internal.loader.ClassLoaders$AppClassLoader@67424e82]
        at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:485)
        at org.springframework.util.ReflectionUtils.doWithLocalMethods(ReflectionUtils.java:321)
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:267)
        ... 28 common frames omitted
Caused by: java.lang.NoClassDefFoundError: org/grails/core/cfg/DeprecatedGrailsConfig
        at java.base/java.lang.Class.getDeclaredMethods0(Native Method)
        at java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3166)
        at java.base/java.lang.Class.getDeclaredMethods(Class.java:2309)
        at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:467)
        ... 30 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.grails.core.cfg.DeprecatedGrailsConfig
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
        ... 34 common frames omitted

Solution

  • I had the same issue, basically one of my dependencies was adding:

    +--- org.grails:grails-datastore-rest-client:5.0.1.RELEASE
    |    +--- org.codehaus.groovy:groovy:2.4.5 -> 2.5.14
    |    +--- commons-codec:commons-codec:1.5 -> 1.13
    |    +--- org.grails:grails-plugin-converters:3.0.12
    

    which caused the issue. You can call gradlew dependencies to see all your dependencies and where they come from Definitely 3.0.12 is not compatible with Grails 4 or 5

    When I removed that dependency converters version bumped to 4.0.1 and project started