Skip to content

Commit 2fc3247

Browse files
authored
Merge pull request #934 from grails/merge-6.2.x-into-7.0.x-12-19-2024
Merge 6.2.x into 7.0.x
2 parents 73aebe8 + ab02ddd commit 2fc3247

File tree

73 files changed

+3964
-18
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+3964
-18
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
Since Grails 3.1, Grails supports a profile for creating applications with AngularJS that provides a more focused set of dependencies and commands. The angular profile inherits from the REST profile and therefore has all of the commands and properties that the REST profile has.
2+
3+
To get started with the AngularJS profile, create an application specifying `angularjs` as the name of the profile:
4+
5+
[source,bash]
6+
----
7+
$ grails create-app my-api --profile angularjs
8+
----
9+
10+
This will create a new Grails application that provides the following features:
11+
12+
* Default set of commands for creating AngularJS artefacts
13+
* Gradle plugin to manage client side dependencies
14+
* Gradle plugin to execute client side unit tests
15+
* Asset Pipeline plugins to ease development
16+
17+
By default the AngularJS profile includes GSP support in order to render the index page. This is necessary because the profile is designed around asset pipeline.
18+
19+
The new commands are:
20+
21+
* `create-ng-component`
22+
* `create-ng-controller`
23+
* `create-ng-directive`
24+
* `create-ng-domain`
25+
* `create-ng-module`
26+
* `create-ng-service`
27+
28+
29+
30+
==== Project structure
31+
32+
33+
The AngularJS profile is designed around a specific project structure. The `create-ng` commands will automatically create modules where they do not exist.
34+
35+
Example:
36+
[source,bash]
37+
----
38+
$ grails create-ng-controller foo
39+
----
40+
41+
This will produce a `fooController.js` file in `grails-app/assets/javascripts/${default package name}/controllers`.
42+
43+
NOTE: By default the angularjs profile will create files in the `javascripts` directory. You can change that behavior in your configuration with the key `grails.codegen.angular.assetDir`.
44+
45+
[source,bash]
46+
----
47+
$ grails create-ng-domain foo.bar
48+
----
49+
50+
This will produce a `Bar.js` file in `grails-app/assets/javascripts/foo/domains`. It will also create the "foo" module if it does not already exist.
51+
52+
[source,bash]
53+
----
54+
$ grails create-ng-module foo.bar
55+
----
56+
57+
This will produce a `foo.bar.js` file in `grails-app/assets/javascripts/foo/bar`. Note the naming convention for modules is different than other artefacts.
58+
59+
[source,bash]
60+
----
61+
$ grails create-ng-service foo.bar --type constant
62+
----
63+
64+
This will produce a `bar.js` file in `grails-app/assets/javascripts/foo/services`. It will also create the "foo" module if it does not already exist. The `create-ng-service` command accepts a flag `-type`. The types that can be used are:
65+
66+
* service
67+
* factory _default_
68+
* value
69+
* provider
70+
* constant
71+
72+
Along with the artefacts themselves, the profile will also produce a skeleton unit test file under `src/test/javascripts` for each create command.
73+
74+
75+
==== Client side dependencies
76+
77+
78+
The https://github.com/craigburke/bower-installer-gradle[Gradle Bower Plugin] is used to manage dependencies with bower. Visit the plugin documentation to learn how to use the plugin.
79+
80+
81+
==== Unit Testing
82+
83+
84+
The https://github.com/craigburke/karma-gradle[Gradle Karma Plugin] is used to execute client side unit tests. All generated tests are written with Jasmine. Visit the plugin documentation to learn how to use the plugin.
85+
86+
87+
==== Asset Pipeline
88+
89+
90+
The AngularJS profile includes several asset pipeline plugins to make development easier.
91+
92+
* https://github.com/craigburke/js-closure-wrap-asset-pipeline[JS Closure Wrap Asset Pipeline] will wrap your Angular code in immediately invoked function expressions.
93+
* https://github.com/craigburke/angular-annotate-asset-pipeline[Annotate Asset Pipeline] will annotate your dependencies to be safe for minification.
94+
* https://github.com/craigburke/angular-template-asset-pipeline[Template Asset Pipeline] will put your templates into the `$templateCache` to prevent http requests to retrieve the templates.

src/en/guide/REST/angularProfile.adoc

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
Since Grails 3.2.1, Grails supports a profile for creating applications with Angular that provides a more future facing setup.
2+
3+
The biggest change in this profile is that the profile creates a multi project gradle build. This is the first profile to have done so. The Angular profile relies on the https://github.com/angular/angular-cli[Angular CLI] to manage the client side application. The server side application is the same as an application created with the `rest-api` profile.
4+
5+
To get started with the Angular profile, create an application specifying `angular` as the name of the profile:
6+
7+
[source,bash]
8+
----
9+
$ grails create-app my-app --profile angular
10+
----
11+
12+
This will create a `my-app` directory with the following contents:
13+
14+
[source]
15+
----
16+
client/
17+
gradle/
18+
gradlew
19+
gradlew.bat
20+
server/
21+
settings.gradle
22+
----
23+
24+
The entire client application lives in the `client` folder and the entire server application lives in the `server` folder.
25+
26+
==== Prerequisites
27+
28+
To use this profile, you should have Node, NPM, and the Angular CLI installed. Node should be at least version 5 and NPM should be at least version 3.
29+
30+
* https://docs.npmjs.com/getting-started/installing-node[Node && NPM]
31+
* https://github.com/angular/angular-cli#installation[Angular CLI]
32+
33+
==== Project Structure
34+
35+
The Angular profile is designed to be used with the https://github.com/angular/angular-cli[Angular CLI]. The CLI was used to create the client application side of the profile to start with. The CLI provides commands to do most of the things you would want to do with the client application, including creating components or services. Because of that, the profile itself provides no commands to do those same things.
36+
37+
==== Running The App
38+
39+
To execute the server side application only, you can execute the `bootRun` task in the `server` project:
40+
41+
[source,bash]
42+
----
43+
./gradlew server:bootRun
44+
----
45+
46+
The same can be done for the client application:
47+
48+
[source,bash]
49+
----
50+
./gradlew client:bootRun
51+
----
52+
53+
To execute both, you must do so in parallel:
54+
55+
[source,bash]
56+
----
57+
./gradlew bootRun --parallel
58+
----
59+
60+
NOTE: It is necessary to do so in parallel because by default Gradle executes tasks synchronously, and neither of the `bootRun` tasks will "finish".
61+
62+
==== Testing
63+
64+
The default client application that comes with the profile provides some tests that can be executed. To execute tests in the application:
65+
66+
[source,bash]
67+
----
68+
./gradlew test
69+
----
70+
71+
The `test` task will execute unit tests with Karma and Jasmine.
72+
73+
[source,bash]
74+
----
75+
./gradlew integrationTest
76+
----
77+
78+
The `integrationTest` task will execute e2e tests with Protractor.
79+
80+
TIP: You can execute the `test` and `integrationTest` tasks on each of the sub-projects the same as you would `bootRun`.
81+
82+
==== CORS
83+
84+
Because the client side and server side will be running on separate ports, CORS configuration is required. By default the profile will configure the server side to allow CORS from all hosts via the following config:
85+
86+
[source,yaml]
87+
.server/grails-app/conf/application.yml
88+
----
89+
grails:
90+
cors:
91+
enabled: true
92+
----
93+
94+
See the section on link:theWebLayer.html#cors[CORS] in the user guide for information on configuring this feature for your needs.

src/en/guide/REST/jsonViews/jsonViewsSetup.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
If you are using the REST application, then the JSON views plugin will already be included and you can skip the remainder of this section. Otherwise you will need to modify your `build.gradle` to include the necessary plugin to activate JSON views:
1+
If you are using the REST application or REST or AngularJS profiles, then the JSON views plugin will already be included and you can skip the remainder of this section. Otherwise you will need to modify your `build.gradle` to include the necessary plugin to activate JSON views:
22

33
[source,groovy]
44
----

src/en/guide/REST/restProfile.adoc

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,36 @@
11
Since Grails 3.1, Grails supports a tailored profile for creating REST applications that provides a more focused set of dependencies and commands.
22

3+
To get started with the REST profile, create an application specifying `rest-api` as the name of the profile:
4+
5+
[source,bash]
6+
----
7+
$ grails create-app my-api --profile rest-api
8+
----
9+
10+
This will create a new REST application that provides the following features:
11+
12+
* Default set of commands for creating and generating REST endpoints
13+
* Defaults to using JSON views for rendering responses (see the next section)
14+
* Fewer plugins than the default Grails plugin (no GSP, no Asset Pipeline, nothing HTML related)
15+
16+
You will notice for example in the `grails-app/views` directory that there are `*.gson` files for rendering the default index page and as well as any 404 and 500 errors.
17+
18+
If you issue the following set of commands:
19+
20+
[source,bash]
21+
----
22+
$ grails create-domain-class my.api.Book
23+
$ grails generate-all my.api.Book
24+
----
25+
26+
Instead of CRUD HTML interface a REST endpoint is generated that produces JSON responses. In addition, the generated functional and unit tests by default test the REST endpoint.
27+
28+
29+
30+
31+
32+
Using Grails Forge, Grails supports a tailored profile for creating REST applications that provides a more focused set of dependencies and commands.
33+
334
To get started with a REST API-type application:
435

536
[source,console]

src/en/guide/commandLine.adoc

Lines changed: 107 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,110 @@
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.
2108

3109
=== Accessing the Grails CLI
4110

0 commit comments

Comments
 (0)