Grails Goodness: Using Aliases as Command Shortcuts
Join the DZone community and get the full member experience.Join For Free
In Grails we can add aliases for standard Grails commands with the
alias command. For example we want to use another name for a command or combine a command with arguments to a single alias. With the following command we create a
start-app alias for the standard
$ grails alias start-app run-app Alias start-app with value run-app configured $
Now we can invoke
$ grails start-app as an alternative for
run-app. All aliases are stored in the file
userHome/.grails/.aliases. This means the aliases we create are available for all Grails versions and applications of the current user. It is also good to notice than command arguments that start with
-- are not saved as part of an alias. But for example the
unit: argument for
test-app can be part of an alias:
$ grails alias unitTest test-app unit: Alias unitTest with value test-app unit: configured $
We can even specify test class patterns to be part of the alias. We then invoke the new alias with extra arguments
$ grails alias test-controllers test-app unit: *Controller Alias test-controllers with value test-app unit: *Controller configured $ grails test-controllers -echoOut -echoErr ... $
To delete an alias we can remove it from the file
userHome/.grails/.aliases or use
$ grails alias --delete=alias.
We can see which aliases are defined with the
$ grails alias --list test-controllers = test-app unit: *Controller start-app = run-app unitTest = test-app unit: $
Published at DZone with permission of Hubert Klein Ikkink, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.