-
Notifications
You must be signed in to change notification settings - Fork 97
Add Grails 8 creating-your-first-grails-app guide. #532
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sanjana2505006
wants to merge
3
commits into
apache:master
Choose a base branch
from
sanjana2505006:creating-your-first-grails-app-v8
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
guides/creating-your-first-grails-app/v8/guide/assetPipeline.adoc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| The web starter ships with the Asset Pipeline plugin (`cloud.wondrify:asset-pipeline-grails`). It manages CSS, JavaScript, and images under `grails-app/assets/` and exposes them with `<asset:*>` tags. | ||
|
|
||
| Common tags: | ||
|
|
||
| [source,xml] | ||
| ---- | ||
| <asset:javascript src="application.js"/> | ||
| <asset:stylesheet src="application.css"/> | ||
| <asset:image src="grails.svg" alt="Grails Logo"/> | ||
| ---- | ||
|
|
||
| Convention: | ||
|
|
||
| * `grails-app/assets/javascripts` for JS | ||
| * `grails-app/assets/stylesheets` for CSS | ||
| * `grails-app/assets/images` for images | ||
|
|
||
| The default layout already wires the manifests: | ||
|
|
||
| [source,gsp] | ||
| .grails-app/views/layouts/main.gsp | ||
| ---- | ||
| <head> | ||
| ... | ||
| <asset:link rel="icon" href="favicon.ico" type="image/x-ico"/> | ||
| <asset:stylesheet src="application.css"/> | ||
| ... | ||
| </head> | ||
| <body> | ||
| ... | ||
| <asset:image src="grails.svg" alt="Grails Logo"/> | ||
| ... | ||
| <asset:javascript src="application.js"/> | ||
| </body> | ||
| ---- | ||
|
|
||
| `application.css` and `application.js` are manifest files. In Grails 8 they pull Bootstrap and jQuery from WebJars: | ||
|
|
||
| [source,css] | ||
| .grails-app/assets/stylesheets/application.css | ||
| ---- | ||
| include::../snippets/grails-app/assets/stylesheets/application.css[] | ||
| ---- | ||
|
|
||
| [source,javascript] | ||
| .grails-app/assets/javascripts/application.js | ||
| ---- | ||
| include::../snippets/grails-app/assets/javascripts/application.js[] | ||
| ---- | ||
|
|
||
| To add your own script, create `grails-app/assets/javascripts/site.js` and require it from the manifest: | ||
|
|
||
| [source,javascript] | ||
| .grails-app/assets/javascripts/application.js | ||
| ---- | ||
| //= require webjars/jquery/%/dist/jquery.js | ||
| //= require webjars/bootstrap/%/dist/js/bootstrap.bundle.js | ||
| //= require site | ||
| //= require_self | ||
| ---- | ||
|
|
||
| [source,javascript] | ||
| .grails-app/assets/javascripts/site.js | ||
| ---- | ||
| console.log('site.js loaded') | ||
| ---- | ||
|
|
||
| Reload http://localhost:8080/ and check the browser console. The same pattern works for CSS: add a file under `stylesheets/` and `*= require` it from `application.css`. | ||
|
|
||
| At build time Asset Pipeline concatenates and can minify these assets for production. |
39 changes: 39 additions & 0 deletions
39
guides/creating-your-first-grails-app/v8/guide/controllers.adoc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| Map the root URL to a home controller and use scaffolding for Make / Model CRUD. | ||
|
|
||
| Point `/` at `HomeController`: | ||
|
|
||
| [source,groovy] | ||
| .grails-app/controllers/example/UrlMappings.groovy | ||
| ---- | ||
| include::../snippets/grails-app/controllers/example/UrlMappings.groovy[] | ||
| ---- | ||
|
|
||
| `HomeController` lists vehicles and lets the visitor update a session name: | ||
|
|
||
| [source,groovy] | ||
| .grails-app/controllers/example/HomeController.groovy | ||
| ---- | ||
| include::../snippets/grails-app/controllers/example/HomeController.groovy[] | ||
| ---- | ||
|
|
||
| For `Make` and `Model`, Grails 8 scaffolding is annotation-based: | ||
|
|
||
| [source,groovy] | ||
| .grails-app/controllers/example/MakeController.groovy | ||
| ---- | ||
| include::../snippets/grails-app/controllers/example/MakeController.groovy[] | ||
| ---- | ||
|
|
||
| [source,groovy] | ||
| .grails-app/controllers/example/ModelController.groovy | ||
| ---- | ||
| include::../snippets/grails-app/controllers/example/ModelController.groovy[] | ||
| ---- | ||
|
|
||
| `VehicleController` is a hand-written CRUD controller. The `show` action adds an estimated value from `ValueEstimateService`: | ||
|
|
||
| [source,groovy] | ||
| .grails-app/controllers/example/VehicleController.groovy | ||
| ---- | ||
| include::../snippets/grails-app/controllers/example/VehicleController.groovy[] | ||
| ---- |
14 changes: 14 additions & 0 deletions
14
guides/creating-your-first-grails-app/v8/guide/creatingTheApp.adoc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| You can recreate `initial/` yourself with the Grails Application Forge: | ||
|
|
||
| [source,bash] | ||
| ---- | ||
| curl -O https://start.grails.org/creating-your-first-grails-app.zip \ | ||
| -d version=8.0.0-SNAPSHOT \ | ||
| -d profile=web \ | ||
| -d features=gsp,hibernate5,scaffolding,geb,h2 | ||
| unzip creating-your-first-grails-app.zip | ||
| ---- | ||
|
|
||
| Or use the https://start.grails.org[web UI], choose Grails 8, the `web` profile, and the features you need, then download the zip. | ||
|
|
||
| This guide uses the cloned `initial/` / `complete/` trees so paths and package names (`example`) stay consistent with the sample. |
27 changes: 27 additions & 0 deletions
27
guides/creating-your-first-grails-app/v8/guide/domainClasses.adoc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| Model a simple vehicle inventory with three domain classes under `grails-app/domain/example/`. | ||
|
|
||
| `Make` is a plain name: | ||
|
|
||
| [source,groovy] | ||
| .grails-app/domain/example/Make.groovy | ||
| ---- | ||
| include::../snippets/grails-app/domain/example/Make.groovy[] | ||
| ---- | ||
|
|
||
| `Model` belongs to a `Make`: | ||
|
|
||
| [source,groovy] | ||
| .grails-app/domain/example/Model.groovy | ||
| ---- | ||
| include::../snippets/grails-app/domain/example/Model.groovy[] | ||
| ---- | ||
|
|
||
| `Vehicle` ties name, year, make, and model together: | ||
|
|
||
| [source,groovy] | ||
| .grails-app/domain/example/Vehicle.groovy | ||
| ---- | ||
| include::../snippets/grails-app/domain/example/Vehicle.groovy[] | ||
| ---- | ||
|
|
||
| GORM maps these classes to tables automatically when you run the app against H2 (the starter default). |
14 changes: 14 additions & 0 deletions
14
guides/creating-your-first-grails-app/v8/guide/gettingStarted.adoc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| Clone the repository and verify the starter project: | ||
|
|
||
| [source,bash] | ||
| ---- | ||
| git clone -b grails8 https://github.com/grails-guides/creating-your-first-grails-app.git | ||
| cd creating-your-first-grails-app/initial | ||
| ./gradlew test | ||
| ---- | ||
|
|
||
| The `initial/` project is a Grails 8 web starter from https://start.grails.org[start.grails.org] (`web` profile, GSP, H2, scaffolding, Spock, Geb). It has no domain model yet. | ||
|
|
||
| To skip ahead, `cd ../complete` and run the same commands; that tree contains the finished Make / Model / Vehicle sample. | ||
|
|
||
| Both `initial` and `complete` must pass in CI (see `.github/workflows/grails8.yml`). |
1 change: 1 addition & 0 deletions
1
guides/creating-your-first-grails-app/v8/guide/helpWithGrails.adoc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| include::{commondir}/common-helpWithGrails.adoc[] |
3 changes: 3 additions & 0 deletions
3
guides/creating-your-first-grails-app/v8/guide/introduction.adoc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| Build a first Apache Grails 8 web application: domain classes, controllers, GSP views, Asset Pipeline, GORM data services, scaffolding, and Spock tests. | ||
|
|
||
| This guide follows the standard Grails guides layout: work in the `initial/` project and compare your progress with `complete/`. |
5 changes: 5 additions & 0 deletions
5
guides/creating-your-first-grails-app/v8/guide/requirements.adoc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| * Approximately 60 minutes | ||
| * JDK 21 (Apache Grails 8 requires Java 21) | ||
| * A text editor or IDE | ||
| * The Gradle wrapper bundled in `initial/` and `complete/` (no separate Grails SDK install required) | ||
| * Docker, if you want to run Geb integration tests (`./gradlew integrationTest`) |
10 changes: 10 additions & 0 deletions
10
guides/creating-your-first-grails-app/v8/guide/runningTheApp.adoc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| From `complete/` (or your working copy of `initial/` once you have added the domain model): | ||
|
|
||
| [source,bash] | ||
| ---- | ||
| ./gradlew bootRun | ||
| ---- | ||
|
|
||
| Open http://localhost:8080/[http://localhost:8080/]. You should see the home page with seeded vehicles. Try `/vehicle/index`, `/make/index`, and `/model/index` as well. | ||
|
|
||
| The default server port is `8080`. To change it, set `server.port` in `grails-app/conf/application.yml` or pass `-Dserver.port=8090` to Gradle. |
37 changes: 37 additions & 0 deletions
37
guides/creating-your-first-grails-app/v8/guide/services.adoc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| Prefer GORM data services for persistence and a small transactional service for domain logic. | ||
|
|
||
| Data services seed `BootStrap` without writing repository boilerplate: | ||
|
|
||
| [source,groovy] | ||
| .grails-app/services/example/MakeService.groovy | ||
| ---- | ||
| include::../snippets/grails-app/services/example/MakeService.groovy[] | ||
| ---- | ||
|
|
||
| [source,groovy] | ||
| .grails-app/services/example/ModelService.groovy | ||
| ---- | ||
| include::../snippets/grails-app/services/example/ModelService.groovy[] | ||
| ---- | ||
|
|
||
| [source,groovy] | ||
| .grails-app/services/example/VehicleService.groovy | ||
| ---- | ||
| include::../snippets/grails-app/services/example/VehicleService.groovy[] | ||
| ---- | ||
|
|
||
| `BootStrap` uses those services to insert sample rows on startup: | ||
|
|
||
| [source,groovy] | ||
| .grails-app/init/example/BootStrap.groovy | ||
| ---- | ||
| include::../snippets/grails-app/init/example/BootStrap.groovy[] | ||
| ---- | ||
|
|
||
| `ValueEstimateService` is a regular Grails service used by `VehicleController.show`: | ||
|
|
||
| [source,groovy] | ||
| .grails-app/services/example/ValueEstimateService.groovy | ||
| ---- | ||
| include::../snippets/grails-app/services/example/ValueEstimateService.groovy[] | ||
| ---- |
10 changes: 10 additions & 0 deletions
10
guides/creating-your-first-grails-app/v8/guide/summary.adoc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| You built a first Grails 8 web app: | ||
|
|
||
| * Domain classes for `Make`, `Model`, and `Vehicle` | ||
| * Annotation scaffolding for Make / Model and a custom `VehicleController` | ||
| * GSP views with Fields tags and a home page that lists seeded vehicles | ||
| * Asset Pipeline manifests for CSS, JavaScript, and images (including WebJars) | ||
| * GORM data services plus `ValueEstimateService` | ||
| * Spock unit tests and a Geb integration spec | ||
|
|
||
| Next steps: add validation messages, secure the CRUD actions, or swap H2 for PostgreSQL in production. |
27 changes: 27 additions & 0 deletions
27
guides/creating-your-first-grails-app/v8/guide/testing.adoc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| Unit-test the estimate service with Spock and the Grails testing mixins: | ||
|
|
||
| [source,groovy] | ||
| .src/test/groovy/example/ValueEstimateServiceSpec.groovy | ||
| ---- | ||
| include::../snippets/src/test/groovy/example/ValueEstimateServiceSpec.groovy[] | ||
| ---- | ||
|
|
||
| Run unit tests: | ||
|
|
||
| [source,bash] | ||
| ---- | ||
| ./gradlew test | ||
| ---- | ||
|
|
||
| Geb integration tests use Testcontainers (`ContainerGebSpec`). Docker must be running: | ||
|
|
||
| [source,groovy] | ||
| .src/integration-test/groovy/example/HomePageSpec.groovy | ||
| ---- | ||
| include::../snippets/src/integration-test/groovy/example/HomePageSpec.groovy[] | ||
| ---- | ||
|
|
||
| [source,bash] | ||
| ---- | ||
| ./gradlew integrationTest | ||
| ---- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| GSPs under `grails-app/views/` render the HTML. The home page uses `<g:each>` and `<g:link>`: | ||
|
|
||
| [source,gsp] | ||
| .grails-app/views/home/index.gsp | ||
| ---- | ||
| include::../snippets/grails-app/views/home/index.gsp[] | ||
| ---- | ||
|
|
||
| Vehicle list and form pages use the Fields plugin tags (`<f:table>`, `<f:all>`, `<f:display>`). The list view: | ||
|
|
||
| [source,gsp] | ||
| .grails-app/views/vehicle/index.gsp | ||
| ---- | ||
| include::../snippets/grails-app/views/vehicle/index.gsp[] | ||
| ---- | ||
|
|
||
| The show page displays the estimated value next to the vehicle: | ||
|
|
||
| [source,gsp] | ||
| .grails-app/views/vehicle/show.gsp | ||
| ---- | ||
| include::../snippets/grails-app/views/vehicle/show.gsp[] | ||
| ---- | ||
|
|
||
| Create and edit forms live in `create.gsp` and `edit.gsp` and call `<f:all bean="vehicle"/>`. |
20 changes: 20 additions & 0 deletions
20
...s/creating-your-first-grails-app/v8/snippets/grails-app/assets/javascripts/application.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| // This is a manifest file that'll be compiled into application.js. | ||
| // | ||
| // Any JavaScript file within this directory can be referenced here using a relative path. | ||
| // | ||
| // You're free to add application-wide JavaScript to this file, but it's generally better | ||
| // to create separate JavaScript files as needed. | ||
| // | ||
| //= require webjars/jquery/%/dist/jquery.js | ||
| //= require webjars/bootstrap/%/dist/js/bootstrap.bundle.js | ||
| //= require_self | ||
|
|
||
| if (typeof jQuery !== 'undefined') { | ||
| (function($) { | ||
| $('#spinner').ajaxStart(function() { | ||
| $(this).fadeIn(); | ||
| }).ajaxStop(function() { | ||
| $(this).fadeOut(); | ||
| }); | ||
| })(jQuery); | ||
| } |
14 changes: 14 additions & 0 deletions
14
.../creating-your-first-grails-app/v8/snippets/grails-app/assets/stylesheets/application.css
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| /* | ||
| * This is a manifest file that'll be compiled into application.css, which will include all the files | ||
| * listed below. | ||
| * | ||
| * Any CSS file within this directory can be referenced here using a relative path. | ||
| * | ||
| * You're free to add application-wide styles to this file and they'll appear at the top of the | ||
| * compiled file, but it's generally better to create a new file per style scope. | ||
| * | ||
| *= require webjars/bootstrap/%/dist/css/bootstrap.css | ||
| *= require webjars/bootstrap-icons/%/font/bootstrap-icons.css | ||
| *= require grails.css | ||
| *= require_self | ||
| */ |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not mention
url-mappings?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added
url-mappingsto the v8 tags.Thanks!