I'm working on Grails 4.0.12 and when I try to rel...
# questions
j
I'm working on Grails 4.0.12 and when I try to reload my changes during the runtime they don't get reflected. I've to restart my application for the changes to take effect. Seems like recompiling is not working during the runtime. I tried using IntelliJ as well as from the terminal but observed same behavior. I even tried including springloaded agent but that was giving me TypeRegistry class not found issue. So before proceeding further, I wanted to confirm if I'm going in the right direction or anybody here has faced/resolved this with some other alternative?
r
I noticed that changes during runtime were no longer reflected, but this was with Grails 6.2. Prior to that, it was working.
This might just be coincidence and not relevant since we're using different versions of Grails and Spring Boot, but I wonder if there could be some common underlying cause that has nothing to do with Grails or Spring Boot...
👍 1
j
Thank you @James Fredley I'll check at my end
I tried this but it didn't work
it restarts the whole application automatically
s
Yes. Pretty sure that is intended behaviour. The transition to spring tools meant you can only have the re-start option and not class re-loading automatically from grails 4 upwards.
p
If you're migrating from G3 to G4 (as I'm doing right now...) then G4 doesn't use the class loader to reload the changed class - it restarts the app. I think it's because the class loader plugin hasn't been maintained for a long time and wasn't reliable enough. I'm also looking for good solution to this as it really slows development down.
j
Yup 😕
p
Looking again, though, https://github.com/spring-projects/spring-loaded says it works with G4. Maybe you could just include that plugin yourself and get the reloading back? I haven't tried that yet (still trying to get my integration tests going) but it'll be next on the list.
....and I've just noticed it doesn't work with Java11. Rules it out for me.
What IDE are you using?
This is what I'll be trying out at some point: https://github.com/HotswapProjects/HotswapAgent
j
I'm using IntelliJ
Yup Spring Loaded doesn't work with Java 11, same applies in my case
I was wondering why they are not supporting class re-compiling anymore. Used to work smoothly in Grails 2 and 3
p
If I figure out the steps to get it working for Grails 4 / Java 11, I'll ping you my notes.
j
Thank you very much @pbarker
o
Class reloading works fine in grails 5 for me with jdk11
p
With springloaded? Or did you use something else?
o
Standard grails 5.3
p
Sure it's not just restarting the app?
o
Well I modify controllers and services and reloads
If I modify a domain class seems to restart everything
But I am going to check what you say
p
If you put something like a
println
in
conf/Bootstrap.groovy
, if you see it spit something out then it's restarting the app. I don't know about Dominic but it take a good 20s for my app to restart to the point where I can check the change I just made. Very slow development process!
j
I'm guessing you have a large Grails app. Spring dev tools takes about 2 seconds for my grails 6.2 app vs 9 seconds on initial start. This is on an i7-12800H with 64GB of ram and Amazon Corretto jdk11.0.20_9.
13:05:27.007 [Thread-0] DEBUG org.springframework.boot.devtools.restart.classloader.RestartClassLoader - Created RestartClassLoader org.springframework.boot.devtools.restart.classloader.RestartClassLoader@50b276f
2024-07-29 13:05:28.689  INFO 34636 --- [  restartedMain] admin.Application                        : The following 1 profile is active: "development"
Configuring Spring Security Core ...
... finished configuring Spring Security Core
2024-07-29 13:05:36.054 DEBUG 34636 --- [  restartedMain] admin.BootStrap                          : bootstrap finished...
2024-07-29 13:05:36.064  INFO 34636 --- [  restartedMain] admin.Application                        : Started Application in 9.043 seconds (JVM running for 9.717)
Grails application running at <http://localhost:8080> in environment: development
File ..\ConfigHolder.groovy changed, recompiling...
2024-07-29 13:05:47.486  INFO 34636 --- [  restartedMain] admin.Application                        : The following 1 profile is active: "development"
Configuring Spring Security Core ...
... finished configuring Spring Security Core
2024-07-29 13:05:49.439 DEBUG 34636 --- [  restartedMain] admin.BootStrap                          : bootstrap finished...
2024-07-29 13:05:49.441  INFO 34636 --- [  restartedMain] admin.Application                        : Started Application in 2.198 seconds (JVM running for 23.093)
There has been some exploration of hotswapagent, but there is not a standard defined path for Grails. I haven't tried it since Spring Boot Dev Tools has met my team's needs/expectations to date for Grails 4, 5 and 6. https://github.com/HotswapProjects/HotswapAgent
p
Yes, we have a fairly large, legacy app. It's not the most efficient (yet) so it's relatively slow restarting. I'll be taking a closer look at HotSwapAgent at some point...
j
Same with me Application is relatively very large, so it takes 2-3 mins for application to boot up So wanted to avoid the restart of app for even a tiny change in controllers/services. I agree that for at Domain level, restarting of app is necessary but that should not be the case for controllers, services,src folders etc