"Fossies" - the Fresh Open Source Software Archive

Member "grails-core-5.2.4/grails-docs/src/test/resources/docs/ref/Command Line/create-command.html" (14 Sep 2022, 61715 Bytes) of package /linux/www/grails-core-5.2.4.tar.gz:

Caution: In this restricted "Fossies" environment the current HTML page may not be correctly presentated and may have some non-functional links. You can here alternatively try to browse the pure source code or just view or download the uninterpreted raw source code. If the rendering is insufficient you may try to find and view the page on the grails-core-5.2.4.tar.gz project site itself.

(Quick Reference)



The create-command command creates a new Grails Gradle task and shell command that can be run with the grails command from a terminal window.


The command:

grails create-command MyExample

Creates a class called grails-app/commands/PACKAGE_PATH/MyExampleCommand.groovy such as:

import grails.dev.commands.*

class MyExampleCommand implements ApplicationCommand {

  boolean handle(ExecutionContext ctx) {
      def dataSource = applicationContext.getBean(DataSource)
      return true

Commands can be executed with the runCommand command.

grails run-command my-example

Or as a Gradle task:

gradle runCommand -Pargs="myExample"

If the command you are executing is defined in a plugin that you have declared a dependency on, then you can execute the command in short form like so:

grails my-example

Or as a Gradle task:

gradle myExample

The plugin is required be on both the build classpath and the runtime classpath in build.gradle in order for the short form to work:

buildscript {
  dependencies {
    classpath "org.grails.plugins:myplugin:0.1-SNAPSHOT"
  dependencies {
    runtime "org.grails.plugins:myplugin:0.1-SNAPSHOT"


In order to separate the code generation and build layer, in Grails 3.x scripts created with create-script do not have access to the running application instance.

Instead, Grails 3.x features a new concept called an ApplicationCommand that is invoked via Gradle to perform tasks such as interact with classes in the runtime.