Have a problem creating a war file with Grails 5.3...
# questions
j
Have a problem creating a war file with Grails 5.3.6, with logback reverted to 1.2.7 to retain usage of logback.groovy. All is well until I go to create a war file (via Gradle on Intellij), and get an exception when trying to compile the gson files. Any clues?
Task :compileGsonViews
Failed to instantiate [ch.qos.logback.classic.LoggerContext] Reported exception: java.lang.RuntimeException: Cannot load application metadata:null at grails.util.Metadata.loadFromDefault(Metadata.groovy:161) at grails.util.Metadata.<init>(Metadata.groovy:61) at grails.util.Metadata.getCurrent(Metadata.groovy:118) at grails.util.Environment.resolveCurrentEnvironment(Environment.groovy:286) at grails.util.Environment.cacheCurrentEnvironment(Environment.groovy:312) at grails.util.Environment.getCurrent(Environment.groovy:278) at grails.util.Environment.getCurrentEnvironment(Environment.groovy:322) 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.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:107) at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:323) at groovy.lang.MetaClassImpl.getProperty(MetaClassImpl.java:1956) at groovy.lang.MetaClassImpl.getProperty(MetaClassImpl.java:3843) at org.codehaus.groovy.runtime.callsite.ClassMetaClassGetPropertySite.getProperty(ClassMetaClassGetPropertySite.java:50) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGetProperty(AbstractCallSite.java:329) at Script1.run(Script1.groovy:21) at Script1$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:130) at ch.qos.logback.classic.gaffer.GafferConfigurator.run(GafferConfigurator.groovy:77) at ch.qos.logback.classic.gaffer.GafferConfigurator$run.callCurrent(Unknown Source) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:51) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:171) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:185) at ch.qos.logback.classic.gaffer.GafferConfigurator.run(GafferConfigurator.groovy:44) at ch.qos.logback.classic.gaffer.GafferUtil.runGafferConfiguratorOn(GafferUtil.java:43) at ch.qos.logback.classic.util.ContextInitializer.configureByResource(ContextInitializer.java:67) at ch.qos.logback.classic.util.ContextInitializer.autoConfig(ContextInitializer.java:150) at org.slf4j.impl.StaticLoggerBinder.init(StaticLoggerBinder.java:84) at org.slf4j.impl.StaticLoggerBinder.<clinit>(StaticLoggerBinder.java:55) at org.slf4j.LoggerFactory.bind(LoggerFactory.java:150) at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:124) at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:417) at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:362) at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:388) at io.micronaut.context.env.AbstractPropertySourceLoader.<clinit>(AbstractPropertySourceLoader.java:46) at grails.util.Metadata$_loadFromDefault_closure1.doCall(Metadata.groovy:133) at grails.util.Metadata$_loadFromDefault_closure1.call(Metadata.groovy) at org.codehaus.groovy.runtime.IOGroovyMethods.withStream(IOGroovyMethods.java:1184) at org.codehaus.groovy.runtime.ResourceGroovyMethods.withInputStream(ResourceGroovyMethods.java:1897) at grails.util.Metadata.loadFromDefault(Metadata.groovy:132) at grails.util.Metadata.<init>(Metadata.groovy:61) at grails.util.Metadata.getCurrent(Metadata.groovy:118) at grails.util.Environment.resolveCurrentEnvironment(Environment.groovy:286) at grails.util.Environment.cacheCurrentEnvironment(Environment.groovy:312) at grails.util.Environment.getCurrent(Environment.groovy:278) at grails.util.Environment.<clinit>(Environment.groovy:127) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:348) at org.codehaus.groovy.runtime.callsite.CallSiteArray.lambda$createCallStaticSite$2(CallSiteArray.java:65) at java.security.AccessController.doPrivileged(Native Method) at org.codehaus.groovy.runtime.callsite.CallSiteArray.createCallStaticSite(CallSiteArray.java:63) at org.codehaus.groovy.runtime.callsite.CallSiteArray.createCallSite(CallSiteArray.java:156) 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:130) at grails.views.ViewsEnvironment.<clinit>(ViewsEnvironment.groovy:12) at grails.views.GenericViewConfiguration$Trait$Helper.$init$(GenericViewConfiguration.groovy:42) 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.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:107) at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite$StaticMetaMethodSiteNoUnwrapNoCoerce.invoke(StaticMetaMethodSite.java:149) at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.call(StaticMetaMethodSite.java:89) 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:139) at grails.plugin.json.view.JsonViewConfiguration.<init>(JsonViewConfiguration.groovy:23) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:72) at org.codehaus.groovy.reflection.CachedConstructor.doConstructorInvoke(CachedConstructor.java:59) at groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1826) at groovy.lang.MetaClassImpl.invokeConstructor(MetaClassImpl.java:1615) at org.codehaus.groovy.runtime.InvokerHelper.invokeConstructorOf(InvokerHelper.java:1060) at org.codehaus.groovy.runtime.DefaultGroovyMethods.newInstance(DefaultGroovyMethods.java:18020) at org.codehaus.groovy.runtime.dgm$547.invoke(Unknown Source) at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite$StaticMetaMethodSiteNoUnwrapNoCoerce.invoke(StaticMetaMethodSite.java:149) at org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.call(StaticMetaMethodSite.java:89) 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:130) at grails.views.AbstractGroovyTemplateCompiler.run(AbstractGroovyTemplateCompiler.groovy:140) at grails.plugin.json.view.JsonViewCompiler.main(JsonViewCompiler.groovy:40) Caused by: java.lang.NullPointerException Caused by: java.lang.NullPointerException at io.micronaut.context.env.yaml.YamlPropertySourceLoader.processInput(YamlPropertySourceLoader.java:64) at io.micronaut.context.env.AbstractPropertySourceLoader.read(AbstractPropertySourceLoader.java:117) at grails.util.Metadata$_loadFromDefault_closure1.doCall(Metadata.groovy:133) at grails.util.Metadata$_loadFromDefault_closure1.call(Metadata.groovy) at org.codehaus.groovy.runtime.IOGroovyMethods.withStream(IOGroovyMethods.java:1184) at org.codehaus.groovy.runtime.ResourceGroovyMethods.withInputStream(ResourceGroovyMethods.java:1897) at grails.util.Metadata.loadFromDefault(Metadata.groovy:132) ... 89 more
I just discovered that if I run the Gradle task to compileGsonViews by itself, it completes without error. So, doing it as part of the "war" task is the problem.
a
See if you can get the war file you want by configuring a bootWar task in your build.gradle file
Something like this:
Copy code
war {
    enabled = false
}

bootWar {
    enabled = true
    archiveFileName = "my-app-name.war"
    classpath = classpath.filter { !it.name.startsWith("spring-boot-cli") }
    launchScript()
}
j
Thanks for the idea, but I've tried similar for a war (not a bootWar). The problem is specific to reverting logBack to 1.2.7 in order to use existing logback.groovy files, which have runtime configurations. If not doing that the war builds fine with a logback.xml file. I suppose I'll have to redo all our applications to use xml files, but not quite sure how to do the runtime (startup] time) mods.
a
Fair enough. Maybe try using the Logback plugin for Grails, maintained by @Groovy Duke rather than rolling back Logback itself. From our build.gradle:
Fair enough. Maybe try using the logback-goovy-config plugin for Grails, maintained by @Groovy Duke rather than rolling back Logback itself. From our build.gradle:
Copy code
implementation 'io.github.virtualdogbert:logback-groovy-config:1.12.5'
implementation 'ch.qos.logback:logback-classic:1.2.13'
implementation 'ch.qos.logback:logback-core:1.2.13'
The caveat is that your logback config will have to be named 'logback-config.groovy' rather than 'logback.groovy'. The naming issue is addressed in the 1.13.x branch of the plugin if you use Logback 1.3.x
j
I'll have to do some work this way too I think. Errors related to imports etc, but I haven't looked at the docs yet, so they may be surmountable. Too bad, earlier reverting logback in gradle.properties worked seamlessly except for the inability to create a war.
a
Adding these imports got me where I needed to be so that we could continue using the same config file as before with the updated logback/plugin:
Copy code
import ch.qos.logback.classic.encoder.PatternLayoutEncoder
import ch.qos.logback.core.ConsoleAppender
import ch.qos.logback.core.rolling.RollingFileAppender
import ch.qos.logback.core.rolling.TimeBasedRollingPolicy
import grails.util.Environment
import org.springframework.boot.logging.logback.ColorConverter
import org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter

import java.nio.charset.Charset
You may need more or fewer. I believe that these classes then get checked against the plugin's accept list to plug the security hole that led Logback to drop native groovy configuration in the first place. Running Grails 6, etc., we get a warning about each of these imports now during startup (related to "Script1.groovy") but then everything works as expected. Good luck
j
I'll give those a try later. I really appreciate the help here - I've been pursuing dead ends for a while now.
I've given up on this issue for now. The use of logback-groovy-config required too many mods for my 6 apps and 12 plugins. To get the code upgraded to Grails 5 I'll revert to logback-version=.1.2.7 (or higher), then deal with the logback issue at a later time. The only problem I have with my reverted logback is that the compile-gson-views errors out with a failure, but actually succeeds in compilation - run it a second time and it is up-to-date. Unfortunately the war task runs compile-gson-views the "first time" and errors out.
Just to semi-complete this topic. To use my original logback.groovy files as is I revert logback by adding this line to gradle.properties:
Copy code
logback.version=1.2.7
The only glitch is that when building a war some of the time the Environment var is not detected in grails.util.Environment. A rerun is required and at some point it gets happy and the war succeeds. I'm trying to track down that flakiness, but otherwise this one line mod beats all. Jay
So everything is fine with the Grails 5.3.6 setup, reverting logback to 1.2.7, EXCEPT that the gradle task compileGsonViews bombs out at the very end when trying to use logback. See the very top line, "Failed to instantiate [ch.qos.logback.classic.LoggerContext]" The task completed otherwise, and by rerunning it again, with the classes already built, it succeeds. I can't figure out from the code how to get around this - does anyone have a suggestion? For now, when building a war I clean, explicitly run compileGsonViews (with an exception), then run the war task which succeeds.