grails / grails-views

Additional View Technologies for Grails
Apache License 2.0
57 stars 41 forks source link

Can't get to work with grails 5 #368

Open xpusostomos opened 2 years ago

xpusostomos commented 2 years ago

I'm porting a working application from grails4 to grails5. I've already ported several other apps to grails5 (albeit, not ones that use views-json), so I'm fairly comfortable with the grails5 upgrade process. But in this particular app I upgraded the views-json plugin to 2.2.0. If I don't use "apply plugin", but just add the "implementation" to my dependencies, it works when running in Intellij idea. However, that doesn't work for production. So when I add the "apply plugin", I get this error on startup...

2022-01-31 20:53:35.209  WARN --- [  restartedMain] org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.actuate.autoconfigure.metrics.task.TaskExecutorMetricsAutoConfiguration': Injection of autowired dependencies failed; nested exception is io.micronaut.context.exceptions.NonUniqueBeanException: Multiple possible bean candidates found: [java.util.concurrent.ExecutorService, java.util.concurrent.ExecutorService]
Disconnected from the target VM, address: '127.0.0.1:50556', transport: 'socket'
2022-01-31 20:53:35.331  INFO --- [  restartedMain] org.apache.catalina.core.StandardService : Stopping service [Tomcat]
2022-01-31 20:53:35.347  INFO --- [  restartedMain] org.springframework.boot.autoconfigure.logging.ConditionEvaluationReportLoggingListener :

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-01-31 20:53:35.387 ERROR --- [  restartedMain] org.springframework.boot.SpringApplication : Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.actuate.autoconfigure.metrics.task.TaskExecutorMetricsAutoConfiguration': Injection of autowired dependencies failed; nested exception is io.micronaut.context.exceptions.NonUniqueBeanException: Multiple possible bean candidates found: [java.util.concurrent.ExecutorService, java.util.concurrent.ExecutorService]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:405)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1431)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:619)
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:944)
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:145)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:730)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:412)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:302)
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 test.ng.Application.main(Application.groovy:16)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
Caused by: io.micronaut.context.exceptions.NonUniqueBeanException: Multiple possible bean candidates found: [java.util.concurrent.ExecutorService, java.util.concurrent.ExecutorService]
at io.micronaut.context.DefaultBeanContext.findConcreteCandidate(DefaultBeanContext.java:2331)
at io.micronaut.context.DefaultApplicationContext.findConcreteCandidate(DefaultApplicationContext.java:451)
at io.micronaut.context.DefaultBeanContext.lastChanceResolve(DefaultBeanContext.java:3165)
at io.micronaut.context.DefaultBeanContext.findConcreteCandidateNoCache(DefaultBeanContext.java:3052)
at io.micronaut.context.DefaultBeanContext.findConcreteCandidate(DefaultBeanContext.java:2966)
at io.micronaut.context.DefaultBeanContext.getBeanInternal(DefaultBeanContext.java:2652)
at io.micronaut.context.DefaultBeanContext.getBean(DefaultBeanContext.java:824)
at io.micronaut.spring.context.factory.MicronautBeanFactory.doGetBean(MicronautBeanFactory.java:738)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:283)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.addCandidateEntry(DefaultListableBeanFactory.java:1598)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1562)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveMultipleBeans(DefaultListableBeanFactory.java:1481)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1338)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1300)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.resolveMethodArguments(AutowiredAnnotationBeanPostProcessor.java:759)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:719)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:119)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399)
... 27 common frames omitted

I can't make any sense of it, but it seems to be related to this plugin.

If I use version 2.1.0 of the views-json plugin, I get the following error on startup....

Task :fap:server:compileGsonViews FAILED Execution optimizations have been disabled for task ':fap:server:compileGsonViews' to ensure correctness due to the following reasons:

FAILURE: Build failed with an exception.

And I can't use the 2.0.4 version of the plugin, I guess because it was configured for an older gradle. Do you have any ideas?

chrisbitmead commented 2 years ago

I made an empty grails project:

grails create-app myApp

And I made only one change to the project, I added

classpath "org.grails.plugins:views-gradle:2.2.0"

to the buildscript dependencies. And then I get the "Multiple possible bean candidates found" error as above.

So in my view, 2.2.0 is completely broken. And thus this plugin is unusable with grails 5.

starkleem commented 2 years ago

I have experienced the similar issues with grails 5.

https://stackoverflow.com/questions/70925978/grails-5-gson-views-not-rendoring

puneetbehl commented 2 years ago

@chrisbitmead I am unable to replicate the problem using the steps shared by you. Could you please make sure that you are using Grails 5.1.2?

@starkleem I think the problem described on Stackoverflow is different from the original issue shared here.

ltamaster commented 2 years ago

I have the same issue

Screen Shot 2022-02-01 at 11 24 05

I compared it with the previous version that we used (2.0.0) and the difference seems to be this changed https://github.com/grails/grails-views/commit/25cab090bfaf6d2264b264c7248680b4f611c806#diff-bab08f900cdc8789160b7e74825cf68433382be9d9a632842136ad2fd91dd46cL117

not familiar with the code, but the previous code calls the view.render(model, request, response) which ending loading the content field in MockHttpServletResponse (using GenericGroovyTemplateView.renderMergedOutputModel). My issue is the content is empty and that is why the JSON parser failed

puneetbehl commented 2 years ago

I'm porting a working application from grails4 to grails5. I've already ported several other apps to grails5 (albeit, not ones that use views-json), so I'm fairly comfortable with the grails5 upgrade process. But in this particular app I upgraded the views-json plugin to 2.2.0. If I don't use "apply plugin", but just add the "implementation" to my dependencies, it works when running in Intellij idea. However, that doesn't work for production. So when I add the "apply plugin", I get this error on startup...

2022-01-31 20:53:35.209  WARN --- [  restartedMain] org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.actuate.autoconfigure.metrics.task.TaskExecutorMetricsAutoConfiguration': Injection of autowired dependencies failed; nested exception is io.micronaut.context.exceptions.NonUniqueBeanException: Multiple possible bean candidates found: [java.util.concurrent.ExecutorService, java.util.concurrent.ExecutorService]
Disconnected from the target VM, address: '127.0.0.1:50556', transport: 'socket'
2022-01-31 20:53:35.331  INFO --- [  restartedMain] org.apache.catalina.core.StandardService : Stopping service [Tomcat]
2022-01-31 20:53:35.347  INFO --- [  restartedMain] org.springframework.boot.autoconfigure.logging.ConditionEvaluationReportLoggingListener :

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-01-31 20:53:35.387 ERROR --- [  restartedMain] org.springframework.boot.SpringApplication : Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.actuate.autoconfigure.metrics.task.TaskExecutorMetricsAutoConfiguration': Injection of autowired dependencies failed; nested exception is io.micronaut.context.exceptions.NonUniqueBeanException: Multiple possible bean candidates found: [java.util.concurrent.ExecutorService, java.util.concurrent.ExecutorService]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:405)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1431)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:619)
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:944)
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:145)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:730)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:412)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:302)
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 test.ng.Application.main(Application.groovy:16)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
Caused by: io.micronaut.context.exceptions.NonUniqueBeanException: Multiple possible bean candidates found: [java.util.concurrent.ExecutorService, java.util.concurrent.ExecutorService]
at io.micronaut.context.DefaultBeanContext.findConcreteCandidate(DefaultBeanContext.java:2331)
at io.micronaut.context.DefaultApplicationContext.findConcreteCandidate(DefaultApplicationContext.java:451)
at io.micronaut.context.DefaultBeanContext.lastChanceResolve(DefaultBeanContext.java:3165)
at io.micronaut.context.DefaultBeanContext.findConcreteCandidateNoCache(DefaultBeanContext.java:3052)
at io.micronaut.context.DefaultBeanContext.findConcreteCandidate(DefaultBeanContext.java:2966)
at io.micronaut.context.DefaultBeanContext.getBeanInternal(DefaultBeanContext.java:2652)
at io.micronaut.context.DefaultBeanContext.getBean(DefaultBeanContext.java:824)
at io.micronaut.spring.context.factory.MicronautBeanFactory.doGetBean(MicronautBeanFactory.java:738)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:283)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.addCandidateEntry(DefaultListableBeanFactory.java:1598)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1562)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveMultipleBeans(DefaultListableBeanFactory.java:1481)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1338)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1300)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.resolveMethodArguments(AutowiredAnnotationBeanPostProcessor.java:759)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:719)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:119)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399)
... 27 common frames omitted

The above error might happen because of earlier version of Micronaut. I remember fixing this issue in some recent version. See https://github.com/micronaut-projects/micronaut-spring/pull/240. I am unable to replicate it in a sample application. Could you please share a sample application?

I can't make any sense of it, but it seems to be related to this plugin.

If I use version 2.1.0 of the views-json plugin, I get the following error on startup....

Task :fap:server:compileGsonViews FAILED Execution optimizations have been disabled for task ':fap:server:compileGsonViews' to ensure correctness due to the following reasons:

  • Gradle detected a problem with the following location: 'C:\Users\chris\GIT\ibis\fap\server\build\gson-classes\main'. Reason: Task ':fap:server:bootWarMainClassName' uses this output of task ':fap:server:compileGsonViews' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. Please refer to https://docs.gradle.org/7.2/userguide/validation_problems.html#implicit_dependency for more details about this problem.

FAILURE: Build failed with an exception.

  • What went wrong: Some problems were found with the configuration of task ':fap:server:compileGsonViews' (type 'JsonViewCompilerTask').

    • In plugin 'org.grails.plugins.views-json' type 'grails.views.gradle.json.JsonViewCompilerTask' property 'compileOptions.encoding' is missing an input or output annotation. Reason: A property without annotation isn't considered during up-to-date checking. Possible solutions:
    1. Add an input or output annotation.
    2. Mark it as @internal.

    Please refer to https://docs.gradle.org/7.2/userguide/validation_problems.html#missing_annotation for more details about this problem.

    • In plugin 'org.grails.plugins.views-json' type 'grails.views.gradle.json.JsonViewCompilerTask' property 'compileOptions.forkOptions' is missing an input or output annotation. Reason: A property without annotation isn't considered during up-to-date checking. Possible solutions:
    1. Add an input or output annotation.
    2. Mark it as @internal.

    Please refer to https://docs.gradle.org/7.2/userguide/validation_problems.html#missing_annotation for more details about this problem.

    • In plugin 'org.grails.plugins.views-json' type 'grails.views.gradle.json.JsonViewCompilerTask' property 'compilerName' is missing an input or output annotation. Reason: A property without annotation isn't considered during up-to-date checking. Possible solutions:
    1. Add an input or output annotation.
    2. Mark it as @internal.

    Please refer to https://docs.gradle.org/7.2/userguide/validation_problems.html#missing_annotation for more details about this problem.

    • In plugin 'org.grails.plugins.views-json' type 'grails.views.gradle.json.JsonViewCompilerTask' property 'fileExtension' is missing an input or output annotation. Reason: A property without annotation isn't considered during up-to-date checking. Possible solutions:
    1. Add an input or output annotation.
    2. Mark it as @internal.

    Please refer to https://docs.gradle.org/7.2/userguide/validation_problems.html#missing_annotation for more details about this problem.

    • In plugin 'org.grails.plugins.views-json' type 'grails.views.gradle.json.JsonViewCompilerTask' property 'scriptBaseName' is missing an input or output annotation. Reason: A property without annotation isn't considered during up-to-date checking. Possible solutions:
    1. Add an input or output annotation.
    2. Mark it as @internal.

    Please refer to https://docs.gradle.org/7.2/userguide/validation_problems.html#missing_annotation for more details about this problem.

And I can't use the 2.0.4 version of the plugin, I guess because it was configured for an older gradle. Do you have any ideas?

I believe 2.1.x and 2.0.x is incompatible with Gradle 7.

chrisbitmead commented 2 years ago

@puneetbehl I'm using grails 5.0.3. In my view, grails 5.1 is not ready for prime time.

The sample application is as described above... use grails 5.0.3

grails create-app

and add this plugin

chrisbitmead commented 2 years ago

@puneetbehl If there's a workaround by upgrading micronaut, could you post it here?

puneetbehl commented 2 years ago

@chrisbitmead Yes, you could try setting micronaut.version property in gradle.properties file but I will recommend updating to Grails 5.1.2. Is there any other issue which is stopping you to upgrade?

puneetbehl commented 2 years ago

@xpusostomos Could you please share a sample application using Grails 5.1.2 and Grails Views 2.2.0 which reproduces the above error?

chrisbitmead commented 2 years ago

@puneetbehl do you have a suggestion what to set micronaut.version to? I don't have to set it in build.gradle, only gradle.properties?

I couldn't get grails 5.1 to work with my app when I tried a month ago. I can't remember anymore what the issue was... , but I figured that 5.1 must be too bleeding edge, and decided to go to 5.0.3, and that worked for me. So I don't have a sample of 5.1.2 that breaks. It may well be fixed there, I don't know. It is 5.0.3 where I see the problem.

puneetbehl commented 2 years ago

@chrisbitmead I would recommend updating to 5.1.2. I am not aware of any alternate other than using the default Grails Views version shipped with Grails 5.0.3 .

netbakter commented 2 years ago

Greetings, works with Grails 5.1.7 with the following combination: build.gradle:

buildscript {
    repositories {
        maven { url "https://repo.grails.org/grails/core" }
    }
    dependencies {
        classpath "org.grails:grails-gradle-plugin:$grailsGradlePluginVersion"
        classpath "org.grails.plugins:hibernate5:7.2.2"
        classpath "gradle.plugin.com.github.erdi.webdriver-binaries:webdriver-binaries-gradle-plugin:2.6"
        classpath "com.bertramlabs.plugins:asset-pipeline-gradle:3.3.4"
        //GSON:
        classpath "org.grails.plugins:views-gradle:2.2.1"**
    }
}

and

apply plugin:"idea"
apply plugin:"war"
apply plugin:"org.grails.grails-web"
apply plugin:"com.github.erdi.webdriver-binaries"
apply plugin:"com.bertramlabs.asset-pipeline"
apply plugin:"org.grails.grails-gsp"
//GSON:
apply plugin:"org.grails.plugins.views-json"

and

implementation "org.grails.plugins:views-json:2.0.4"

Yes I know this is a bit mixed up, tried a few combinations and this one does work deployed as a WAR with Tomcat 9.

G.