I’m trying to nail down what the difference is between these three folders and what I should be putting in them.
As of right now I have been throwing class, interfaces, and anything else that directly relates to the structure of my domain classes (by extending or implementing) into the src folder. Anything that involves additional transactional logic beyond what a Grails controller does by default I have been putting into the grails-app/services folder. Lastly, any class that contains “helper” methods (i.e. comparing various things, special string operations, etc.) I have been putting into the grails-app/utils folder.
If I have missed the mark for what these folders should be used for please put me on the right path.
That’s pretty close. grails-app/utils is for Codec classes – it’s weirdly named and underdocumented. I’d move the helper classes back to src/groovy.
Using services to do transactional work is great, but you can use services for non-transactional methods too. Add
static transactional = falseto the service classes that have utility methods that don’t need transactions. Note that there’s no transactionality in controllers, so you should move all persistence to transactional services.Static utility methods in a src/groovy helper class and non-transactional methods in a service are pretty much equivalent, so for me the deciding which route to take would come down to dependencies. If the class depends on Spring beans, make it a service and reference them via dependency injection. Otherwise just make it a helper class.