grails-core icon indicating copy to clipboard operation
grails-core copied to clipboard

Test HotswapAgent http://hotswapagent.org

Open codeconsole opened this issue 1 year ago • 5 comments

Test HotswapAgent http://hotswapagent.org

"we are getting limited grails 6 hotswap behavior with DCEMV /hotswapagent.org. Happy to share what we know and help with that " @lbwexler

Perhaps a good starting place is demonstrating on a super basic app?

codeconsole avatar Jul 29 '24 18:07 codeconsole

Is current HotswapAgent licensed under GPL?

jeffscottbrown avatar Jul 30 '24 12:07 jeffscottbrown

@osscontributor Looks like GPL 2.0

https://github.com/HotswapProjects/HotswapAgent/blob/master/LICENSE https://github.com/HotswapProjects/HotswapAgent?tab=readme-ov-file https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html

Also looks like project is active, but no formal releases since 2020 except for a snapshot that points to 2020 commits. https://github.com/HotswapProjects/HotswapAgent/tags They probably plan on an official release at some point given the activity

What are the implications of the GPL license?

codeconsole avatar Jul 30 '24 16:07 codeconsole

Since it's an agent and not embedded in grails I do not believe the implications are of any concern. This is similar to gpl 2 and MySQL

davydotcom avatar Jul 30 '24 17:07 davydotcom

Agent has had recent updates and contributions as of September! Jdk 21 works now as well

davydotcom avatar Sep 27 '24 14:09 davydotcom

@davydotcom Are we able to use ResetAgent.java instead of groovyReset.jar?

codeconsole avatar Sep 30 '24 18:09 codeconsole

Currently blocked by https://github.com/apache/grails-core/issues/13669#issuecomment-3066110262

jamesfredley avatar Aug 07 '25 20:08 jamesfredley

The following example project has been updated with the latest Grails 7 changes:

https://github.com/jamesfredley/hotswap-demo - this automatically installs and runs the right JDK (only JETBRAINS 17 and 21 work), downloads and installs hotswap-agent.jar from mavenCentral (org.hotswapagent:hotswap-agent:2.0.2) and uses groovyReset.jar.

To replicate the exact steps from: https://www.youtube.com/watch?v=Fz_sKuZ-ytg, although you will see more log errors:

clone https://github.com/jamesfredley/hotswap-demo
./grailsw
create-domain-class Car
// manually add String name to Car domain class
run-app
// view list of controllers on http://localhost:8080/
create-scaffold-controller com.example.Car
// view list of controllers on http://localhost:8080/
// you can create a Car and save, view the list, delete etc.

But other tasks, while Grails is running, such as adding a domain, adding a new field to a domain do not appear to work without a restart. Adding an action to an existing controller works, just make sure the view exists.

./grailsw
run-app
// view list of controllers on http://localhost:8080/
create-domain-class Pet
// manually add String name to Pet domain class
create-scaffold-controller com.example.Pet
// view list of controllers on http://localhost:8080/
// click on PetController
// Error: Either class [com.example.Pet] is not a domain class or GORM has not been initialized correctly or has already been shutdown. Ensure GORM is loaded and configured correctly before calling any methods on a GORM entity.
exit
./grailsw
run-app
// view list of controllers on http://localhost:8080/
// click on PetController, it works fine

jamesfredley avatar Aug 08 '25 15:08 jamesfredley

https://github.com/HotswapProjects/HotswapAgent/issues/581 is relevant

Loading new domain classes, reloading changed domain classes and resolving all of the logged errors may require changes to https://github.com/HotswapProjects/HotswapAgent and it's plugins

jamesfredley avatar Aug 08 '25 15:08 jamesfredley

@jamesfredley were you seeing hotswap working properly at the Service level as well? In Grails 5, domain class changes required a restart I'm pretty sure so that's not a regression. Is that right @brandonray-gs ?

jaGarcia avatar Aug 08 '25 16:08 jaGarcia

@jaGarcia editing an existing service reloads. Creating new service requires a restart.

jamesfredley avatar Aug 08 '25 17:08 jamesfredley

@jamesfredley were you seeing hotswap working properly at the Service level as well? In Grails 5, domain class changes required a restart I'm pretty sure so that's not a regression. Is that right @brandonray-gs ?

Can't recall specifically on domain classes.. believe they did require a restart. Creating new services or injecting other services has always required a restart as well.

brandonray-gs avatar Aug 12 '25 12:08 brandonray-gs

I recall editing Domain classes always being something that required restart.

My usage of hotswap in Grails 5 always required restart for anything like creating new artifacts, editing Domain classes, class and method renames, etc. But this never seemed like a huge concern for me -- 90% of the benefit of hotswap comes from being able to change logic in existing methods.

lbwexler avatar Aug 12 '25 15:08 lbwexler

It sounds like https://github.com/jamesfredley/hotswap-demo is on par with expectation from Grails 5.

jamesfredley avatar Aug 12 '25 18:08 jamesfredley

Here are the changes required to configure Hotswap Agent in an existing application, including automating the download and usage of hotswap-agent.jar and gragent.jar:

https://github.com/jamesfredley/hotswap-demo/commit/fb8386c50f7aad6aee1cefdbc37cc1571ad7d747

jamesfredley avatar Aug 13 '25 13:08 jamesfredley