I'm having trouble figuring out where the template...
# questions
s
I'm having trouble figuring out where the template is for the create-unit-test command. I'm using grails 5.3 and have been getting good mileage out of generate-all to make a consistent baseline when adding new domain classes, but I am not happy with the unit test that gets generated for services. Is there a way to add another template to adjust how unit tests are templated? If not, how hard would it re-use the templating logic in a custom command ( e.g. create a new command with
grailsw create-command my-generate-service
and then run my command with
grailsw my-generate-service domain.className
)? I'm getting a weird behavior where
generate-all
uses the templates under
src/main/templates
but
create-service
seems to resolve the template from somewhere else. Where is the code generation specified? From poking around the grails-scaffolding project it looks like the generate-all and generate-service commands both reference the templates in the same way, but I'm not confident this is the code that's running when I use grailsw commands.
m
Hi, I think the Unit test template for Services is from the web profile: https://github.com/grails-profiles/web/blob/master/templates/testing/Service.groovy. To replace it, I think you would have to create you own profile, possibly inheriting from the web profile, and then you can change whatever you want in there. (But remember, profiles where removed in Grails 6). Another solution, as you suggest, would be to create your own command for creating Service artifacts, it should be fairly straightforward: https://docs.grails.org/latest/guide/commandLine.html#creatingCustomCommands
s
Thank you Mattias! I'll test out a custom command, it does look pretty straightforward. The web profile templates look different, they use @ to mark variable substitution instead of gstrings. It looks like the command are also defined using yaml. Is that a standard grails thing, or something idiosyncratic about these templates? Thanks again for the pointers in the right direction!
👍 1
p
Please note that with Grails 6 we moved away from the concepts of profiles and using YAML for templates.