I'm working with Grails for a project and currentl...
# questions
u
I'm working with Grails for a project and currently using 7.0 M1 I have a project that I created via Grails Forge I've setup hotswap as described at https://github.com/grails/grails-forge/issues/445 It looks like it is at least partially working - when I make a code change in the editor, I do see a message along the lines of
Copy code
File /full/path/to/Request.groovy changed, recompiling...
But when I try to do this with the GroovyConsole, it is clear it continues to use the old class. If I try to add a new controller with the default webapp created by Grails Forge, reloading the page shows the new controller class in the list of controllers. But clicking on it gives a 404 error. Am I doing something wrong? Is there additional configuration I should be adding?
u
To be clear - this is happening for any code change. So if I'm running the console and I change a class to add a method, the console does give the "recompiling..." message, but trying to use the method throws a "groovy.lang.MissingMethodException". If I change a method (so it has the same signature, but different code), I see the "recompiling..." message, but it calls the code that belongs to the previous version
u
(Oops. And I meant to tag @James Fredley on my original question and my followup to see if he has any insights about what I could be doing wrong or a way to diagnose what could be happening.)
j
@scott @davydotcom Any ideas on Allens' question? I haven't had time to experiment with hotswap agent, yet.
@User have you removed the spring-dev-tools dependency? And also wanted to make sure you saw: https://github.com/codeconsole/website/blob/7.0.0-SNAPSHOT/build.gradle#L85
u
Thanks @James Fredley! Yup, I confirmed I was using the JBR version: "JBR-21.0.4+8-569.1-jcef" I don't see the Spring Dev Tools in either the dependencies or any chained dependencies. Looking at the snapshot build.gradle you referenced, however, I did see the
jvmArgs
for bootRun specified a few lines later that I didn't have in my build.gradle. I added these lines:
Copy code
bootRun {
    jvmArgs(
            '-XX:+AllowEnhancedClassRedefinition',
            '-XX:HotswapAgent=fatjar')
}
I omitted the
-javaagent:lib/groovyReset.jar
line that the build.gradle you pointed to had, since it caused an error. I'm guessing this is the groovy jar that @davydotcom references in https://github.com/grails/grails-core/issues/13669 (which I just now found, but which sounds like what I was seeing as well).
g
@User I had issue as you before, but after I change jvmArgs to :
Copy code
bootRun {
    jvmArgs(
            '-XX:+AllowEnhancedClassRedefinition',
            '-DautoHotswap=true',
            '-XX:HotswapAgent=fatjar')
}
This will work, but it throws bunch of errors like:
Copy code
java.lang.reflect.InvocationTargetException
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:118)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	at org.hotswap.agent.plugin.spring.reload.SpringChangedReloadCommand.executeCommand(SpringChangedReloadCommand.java:54)
	at org.hotswap.agent.command.impl.CommandExecutor.run(CommandExecutor.java:43)
Caused by: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
	at org.hotswap.agent.plugin.spring.reload.SpringBeanReload.invokeBeanFactoryPostProcessors(SpringBeanReload.java:655)
	at org.hotswap.agent.plugin.spring.reload.SpringBeanReload.doReload(SpringBeanReload.java:296)
	at org.hotswap.agent.plugin.spring.reload.SpringBeanReload.reload(SpringBeanReload.java:259)
	at org.hotswap.agent.plugin.spring.reload.SpringChangedAgent.doReload(SpringChangedAgent.java:204)
	at org.hotswap.agent.plugin.spring.reload.SpringChangedAgent.reloadAll(SpringChangedAgent.java:192)
	at org.hotswap.agent.plugin.spring.reload.SpringChangedAgent.reload(SpringChangedAgent.java:143)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
	... 3 more
Caused by: java.lang.reflect.InvocationTargetException
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:118)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	at org.hotswap.agent.plugin.spring.reload.SpringBeanReload.invokePostProcessorRegistrationDelegate(SpringBeanReload.java:666)
	at org.hotswap.agent.plugin.spring.reload.SpringBeanReload.invokeBeanFactoryPostProcessors(SpringBeanReload.java:646)
	... 9 more
but it works