|
1 | | -The Grails New Command-Line Interface (CLI) has undergone significant changes compared to its previous versions, primarily focusing on code generation. One notable alteration is the removal of APIs for invoking Gradle for tasks related to building using Gradle Tooling APIs. This shift in responsibility aligns with the framework's evolution and its integration with the Gradle build system. |
| 1 | +Grails 3.0's command line system differs greatly from previous versions of Grails and features APIs for invoking Gradle for build related tasks, as well as performing code generation. |
| 2 | + |
| 3 | +When you type: |
| 4 | + |
| 5 | +[source,groovy] |
| 6 | +---- |
| 7 | +grails <<command name>> |
| 8 | +---- |
| 9 | + |
| 10 | +Grails searches the http://bintray.com/grails/profiles[profile repository] based on the profile of the current application. If the profile is for a web application then commands are read from the web profile and the base profile which it inherits from. |
| 11 | + |
| 12 | +Since command behavior is profile specific the web profile may provide different behavior for the `run-app` command then say a profile for running batch applications. |
| 13 | + |
| 14 | +When you type the following command: |
| 15 | + |
| 16 | +[source,groovy] |
| 17 | +---- |
| 18 | +grails run-app |
| 19 | +---- |
| 20 | + |
| 21 | +It will first search the application, and then the profile for commands: |
| 22 | + |
| 23 | +* `PROJECT_HOME/src/main/scripts/run-app.groovy` |
| 24 | +* `<<profile>>/commands/run-app.groovy` |
| 25 | +* `<<profile>>/commands/run-app.yml` |
| 26 | +
|
| 27 | +To get a list of all commands and some help about the available commands type: |
| 28 | + |
| 29 | +[source,bash] |
| 30 | +---- |
| 31 | +grails help |
| 32 | +---- |
| 33 | + |
| 34 | +which outputs usage instructions and the list of commands Grails is aware of: |
| 35 | + |
| 36 | +[source,bash] |
| 37 | +---- |
| 38 | +grails <<environment>>* <<target>> <<arguments>>*' |
| 39 | +
|
| 40 | +| Examples: |
| 41 | +$ grails dev run-app |
| 42 | +$ grails create-app books |
| 43 | +
|
| 44 | +| Available Commands (type grails help 'command-name' for more info): |
| 45 | +| Command Name Command Description |
| 46 | +---------------------------------------------------------------------------------------------------- |
| 47 | +clean Cleans a Grails application's compiled sources |
| 48 | +compile Compiles a Grails application |
| 49 | +... |
| 50 | +---- |
| 51 | + |
| 52 | +NOTE: Refer to the Command Line reference in the Quick Reference menu of the reference guide for more information about individual commands |
| 53 | + |
| 54 | +=== Arguments |
| 55 | + |
| 56 | +The `grails` command is a front to a `gradle` invocation, because of this there can be unexpected side-effects. |
| 57 | +For example, when executing `grails -Dapp.foo=bar run-app` the `app.foo` system property won't be available to your application. This is because `bootRun` in your `build.gradle` configures the system properties. |
| 58 | +To make this work you can simply append all `System.properties` to `bootRun` in `build.gradle` like: |
| 59 | + |
| 60 | +[source,groovy] |
| 61 | +---- |
| 62 | +bootRun{ |
| 63 | + systemProperties System.properties // Please note not to use '=', because this will override all configured systemProperties. This will append them. |
| 64 | +} |
| 65 | +---- |
| 66 | + |
| 67 | +Or if you only want to pass through a limited set, you can prefix your system properties using an arbitrary prefix and configure `bootRun` like: |
| 68 | + |
| 69 | +[source,groovy] |
| 70 | +---- |
| 71 | +bootRun{ |
| 72 | + bootRun { |
| 73 | + systemProperties System.properties.inject([:]){acc,item-> item.key.startsWith('boot.')?acc << [(item.key.substring('boot.'.length())):item.value]:acc } |
| 74 | + } |
| 75 | +} |
| 76 | +---- |
| 77 | + |
| 78 | +In this example only system properties starting with `boot.` are passed through. |
| 79 | + |
| 80 | +Application and JVM arguments should be specified in `bootRun` as well. |
| 81 | + |
| 82 | +[source,groovy] |
| 83 | +---- |
| 84 | +bootRun{ |
| 85 | + bootRun { |
| 86 | + jvmArgs('-Dspring.output.ansi.enabled=always') |
| 87 | + args('--app.foo=bar','--app.bar=foo') // Override the `app.foo` and `app.bar` config options (`grailsApplication.config`) |
| 88 | + } |
| 89 | +} |
| 90 | +---- |
| 91 | + |
| 92 | + |
| 93 | +=== non-interactive mode |
| 94 | + |
| 95 | + |
| 96 | +When you run a script manually and it prompts you for information, you can answer the questions and continue running the script. But when you run a script as part of an automated process, for example a continuous integration build server, there's no way to "answer" the questions. So you can pass the `\--non-interactive` switch to the script command to tell Grails to accept the default answer for any questions, for example whether to install a missing plugin. |
| 97 | + |
| 98 | +For example: |
| 99 | + |
| 100 | +[source,groovy] |
| 101 | +---- |
| 102 | +grails war --non-interactive |
| 103 | +---- |
| 104 | + |
| 105 | + |
| 106 | + |
| 107 | +The Grails Forge New Command-Line Interface (CLI) has undergone significant changes compared to its previous versions, primarily focusing on code generation. One notable alteration is the removal of APIs for invoking Gradle for tasks related to building using Gradle Tooling APIs. This shift in responsibility aligns with the framework's evolution and its integration with the Gradle build system. |
2 | 108 |
|
3 | 109 | === Accessing the Grails CLI |
4 | 110 |
|
|
0 commit comments