hello community to create a new application for s...
# questions
k
hello community to create a new application for some purpose the minimum that is needed to me is mysql so that the data is not lost on system restart. so is there a way to create a grails app using the command grails create-app myApp that automatically puts all configuration to connect to mysql database? i appreciate any guidance. thank you!
m
@kofhearts I use the new command to generate new app, it supports more options like -db -js -css.
k
@Michael Yan could you please provide an example?
m
@kofhearts you can create a NewCommand like
org.grails.cli.profile.commands.CreateAppCommand
, add it to the classpath in your
$GRAILS_HOME/bin/grails.sh
.
The other choice is using your own Profile to generate the application. https://github.com/rainboyan/web-bootstrap https://github.com/rainboyan/web-clean
s
I believe profiles are no longer part of the new CLI (Grails 6+), so I would avoid using those. You can use features to add chunks of functionality to the created app using the grails cli.
grails create-app --list-features
Gives you a list of available features. TO create an app that uses (GORM with hibernate 5+ and Mysql config settings, use
Copy code
grails create-app --features=gorm-hibernate5,mysql <some.package.name.AppName>
m
@Steve Osguthorpe How to add a new feature which not available on the Grails Forge, but only for my private project? That’s why I prefer to use Profile. But now I’m implementing a new feature called App Template to allow developers easy customise and apply to the generated new App sources.
s
That's a good question... It looks like the profiles have disappeared in favour of first class commands as the cli now offers:
Copy code
*  create-app NAME
*  create-webapp NAME
*  create-restapi NAME
*  create-plugin NAME
*  create-webplugin NAME
Instead of the profile flag. I think given this is only for bootstrapping, this seems like a better fit. I don't know how you would add custom commands though.
m
@Steve Osguthorpe I can install Grails version from Github Releases, not through
sdkman install
. I understand that this is not the officially recommended way, but they didn’t tell you that the profiles and commands are still exist in
grails-shell
, it works if you have some custom profiles.
s
Of course. But given they are refactoring the CLI and that the latest official release has removed profile support in the cli, I wouldn't ever recommend relying on something which has effectively been deprecated and may disappear all together. In our company we don't use the CLI at all, we use gradle directly so it doesn't affect us in any way.
m
We are talking about using
create-app
command to generate a new app, this is not the same thing as what you said about using gradle directly. Do you like the
gradlew runnCommand -Pargs=""
? Oh, it’s ugly, hard to use.
s
I am fully aware that gradle is used after app creation. I'm merely pointing out that we don't use the cli at all. And so we aren't affected by profile support within the CLI disappearing. And yes, we prefer to go directly to the source and use gradle. No need to maintain and update a wrapper api for no reason that way. I was just pointing out that while you recommended a profile to the OP, the support for profiles might disappear all together and the features that do still exists are more stable. That's all.
m
Sorry, perhaps I didn’t make it clear, Grails supports many type of
Command
:
ApplicationCommand
,
ProfileCommand
,
ProjectCommand
,
create-app
is just a
Command
, the
gradle runCommand
task running is
ApplicationCommand
. The CLI is just a code generate tool written by Micronaut CLI, the features and templates inside it you can’t modified for your needs. Spring Boot CLI supports adding extensions to the CLI by using the
install
command, this is what I want: create your own
NewCommand
, and install it to the CLI’s classpath, then you can use it.
k
@Steve Osguthorpe thank you very much for sharing the features example. ill give it a try.
@Michael Yan thanks for sharing the twitter post. ill give it a try.
@Steve Osguthorpe could you please confirm whether the features flag is only available for grails 6?
grails create-app --features=gorm-hibernate5,mysql <some.package.name.AppName>
i am using grails 4.0.10 and is there a way to use this flag for this version of grails. I would like to create a grails 4.0.10 project with mysql8 already configured. thank you!
s
AFAIK features have been part of the CLI from grails 3 ish... The features available may have different names though. Try it out on your machine.
It is worth noting grails 4 is unsupported so I wouldn't recommend starting a new application with already unsupported software.
k
@Steve Osguthorpe thank you steve. if i start a new project, ill start with the latest grails version which is 6.1.2.
👌 1