Over a million developers have joined DZone.

Grails Goodness: Using Aliases as Command Shortcuts

· Java Zone

Bitbucket is for the code that takes us to Mars, decodes the human genome, or drives your next car. What will your code do? Get started with Bitbucket today, it's 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 run-app command:

$ 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 - or -- 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 -echoOut and -echoErr:

$ 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 --list argument:

$ grails alias --list
test-controllers = test-app unit: *Controller
start-app = run-app
unitTest = test-app unit:
$
Code written with Grails 2.3.8.

Bitbucket is the Git solution for professional teams who code with a purpose, not just as a hobby. Get started today, it's free.

Topics:

Published at DZone with permission of Hubert Klein Ikkink, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}