Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 48 additions & 1 deletion conf/guides.yml
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,7 @@ guides:
subtitle: 'Learn how to create your first Grails app'
authors:
- 'Zachary Klein'
- 'Sanjana'
category: 'Grails Apprentice'
publicationDate: '2017-01-23'
versions:
Expand Down Expand Up @@ -687,7 +688,53 @@ guides:
deployment:
title: Deploying your App
helpWithGrails:
title: Do you need help with Grails?
title: Do you need help with Grails?
'8':
sourcePath: guides/creating-your-first-grails-app/v8
publicationDate: '2026-08-05'
tags:
- 'beginner'
- 'domain-classes'
- 'controllers'
- 'services'
- 'gsp'
- 'unit-tests'
- 'integration-tests'
- 'scaffolding'
- 'asset-pipeline'
- 'url-mappings'
- 'getting-started'
- 'crud'

Copy link
Copy Markdown
Contributor

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added url-mappings to the v8 tags.
Thanks!

sampleRef:
repo: 'grails-guides/creating-your-first-grails-app'
branch: 'grails8'
toc:
introduction:
title: Introduction
requirements:
title: What you will need
gettingStarted:
title: Getting Started
creatingTheApp:
title: Creating the app
runningTheApp:
title: Running the app
domainClasses:
title: Domain classes
controllers:
title: Controllers and scaffolding
views:
title: GSP views
assetPipeline:
title: Asset Pipeline
services:
title: Services
testing:
title: Testing
summary:
title: Summary
helpWithGrails:
title: Do you need help with Grails?

- name: 'database-per-tenant'
title: 'Database per Tenant Multi-Tenancy'
Expand Down
70 changes: 70 additions & 0 deletions guides/creating-your-first-grails-app/v8/guide/assetPipeline.adoc
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 guides/creating-your-first-grails-app/v8/guide/controllers.adoc
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 guides/creating-your-first-grails-app/v8/guide/creatingTheApp.adoc
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 guides/creating-your-first-grails-app/v8/guide/domainClasses.adoc
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 guides/creating-your-first-grails-app/v8/guide/gettingStarted.adoc
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`).
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include::{commondir}/common-helpWithGrails.adoc[]
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/`.
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 guides/creating-your-first-grails-app/v8/guide/runningTheApp.adoc
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 guides/creating-your-first-grails-app/v8/guide/services.adoc
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 guides/creating-your-first-grails-app/v8/guide/summary.adoc
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 guides/creating-your-first-grails-app/v8/guide/testing.adoc
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
----
25 changes: 25 additions & 0 deletions guides/creating-your-first-grails-app/v8/guide/views.adoc
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"/>`.
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);
}
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
*/
Loading