Skip to content

Start every context of a GrailsAppBuilder hierarchy with a GrailsApp - #16462

Merged
jdaugherty merged 1 commit into
8.0.xfrom
fix/grails-app-builder-hierarchies
Oct 2, 2026
Merged

jdaugherty merged 1 commit into
8.0.xfrom
fix/grails-app-builder-hierarchies

Conversation

@jdaugherty

Copy link
Copy Markdown
Contributor

Description

Bug fix split out of #16456, as discussed in its review.

GrailsAppBuilder only swapped in a GrailsApp for the builder it was constructed as. Spring Boot's child(), parent() and sibling() still produced plain SpringApplicationBuilders, so a hierarchy lost the Grails startup defaults, and because the plain parent was launched by a GrailsApp it ran the plugin lifecycle too: on 8.0.x, new GrailsAppBuilder(Shared).child(Application).run(args) fails with No bean named 'classLoader' available while creating groovyPagesTemplateEngine in the parent.

The builder now owns the hierarchy itself and overrides every Boot fluent method with a covariant GrailsAppBuilder return, so every context of a hierarchy is started by a GrailsApp. GrailsApp records the members of a hierarchy (a package-scoped flag the builder sets) and runs the plugin lifecycle in the one whose sources include the Grails application class, logging at INFO when a member leaves it out. A standalone GrailsApp keeps running the lifecycle whatever its sources are. The development-mode watch starts only in the context that owns the plugin manager.

Covered by GrailsAppBuilderSpec, GrailsAppContextHierarchySpec, a hierarchy feature of DevelopmentModeWatchSpec, and two example applications: a shared Spring parent with a Grails web child, and a command-line program with a non-web Grails parent and a Spring child. Documented in a short section of "Executing the Application Class".

What stays in #16456 for 8.1: registering grailsApplication and pluginManager locally in every context and withdrawing them from the parent when the Grails child closes or fails to start, the refusal of a second Grails application in one hierarchy, the run-status line for contexts without a web server, the public contextHierarchyMember property, and the full "Building the Application" page.

Contributor Checklist

Issue and Scope

Code Quality

  • I have added or updated tests that cover the changes introduced in this PR.
  • The covering specs and both example applications pass; CI runs the full build.
  • My code follows the project's code style guidelines (:grails-core:codeStyle is clean).
  • This PR does not include mass reformatting, style-only changes, or large-scale refactoring.
  • Not applicable.

Licensing and Attribution

  • All contributed code is provided under the Apache License 2.0, and new source files include the Apache license header.
  • I have the necessary rights to submit this contribution and confirm it is my own original work.
  • Not applicable.

GrailsAppBuilder only swapped in a GrailsApp for the builder it was
constructed as; Spring Boot's child(), parent() and sibling() still
produced plain SpringApplicationBuilders, so a hierarchy lost the Grails
startup defaults and the parent of a Grails web child failed to start
with "No bean named 'classLoader' available", because the plain parent,
launched by a GrailsApp, ran the plugin lifecycle too.

The builder now owns the hierarchy itself and overrides every Boot
fluent method with a covariant return, so a chain stays in Grails terms
and every context of a hierarchy is started by a GrailsApp. GrailsApp
records the members of a hierarchy and runs the plugin lifecycle in the
one whose sources include the Grails application class, logging when a
member leaves it out; a standalone GrailsApp keeps running the lifecycle
whatever its sources are. The development-mode watch starts only in the
context that owns the plugin manager.

Covered by GrailsAppBuilderSpec, GrailsAppContextHierarchySpec, a
hierarchy feature of DevelopmentModeWatchSpec and two example
applications: a shared Spring parent with a Grails web child, and a
command-line program with a non-web Grails parent and a Spring child.
Documented in a short section of "Executing the Application Class".
@jdaugherty
jdaugherty requested a review from matrei October 1, 2026 16:25
@jdaugherty jdaugherty added this to the grails:8.0.0 milestone Oct 1, 2026
jdaugherty added a commit that referenced this pull request Oct 1, 2026
Builds on the 8.0.x fix that starts every context of a GrailsAppBuilder
hierarchy with a GrailsApp (#16462), and settles what a hierarchy means
for the Grails lifecycle, which keeps JVM-wide state: Holders, the
initializing flag, the shutdown operations and the development watch.

Exactly one context of a hierarchy is the Grails application. A context
whose parent chain already holds a grailsApplication refuses to start as
a second one. GrailsApplicationPostProcessor registers grailsApplication
and pluginManager locally in every context and lends them to the parent,
and takes the loan back in DisposableBean.destroy(), which Spring runs
on a normal close and on a failed refresh alike, so a parent that
outlives its Grails child holds nothing of it and another Grails child
can start beneath it; a parent bean that injected the lent singletons is
destroyed with them and recreated against the next loan, and the docs
point parent beans at ObjectProvider instead. The contextHierarchyMember
flag the builder sets becomes a public GrailsApp property, so a
hierarchy assembled by hand can set it. No running address is reported
for a context without a web server.

Documented in a new "Building the Application" page and the what's new
section, which replace the short section the fix added to "Executing the
Application Class", and exercised by the second-application refusal and
loan-return specs and by the web example's sibling-refusal spec.
@jdaugherty

Copy link
Copy Markdown
Contributor Author

@matrei this is the 8.0.x half of #16456, split out as you suggested in your review there: GrailsAppBuilder owning its hierarchy with covariant overrides (plus build() returning GrailsApp), the hierarchy-member flag on GrailsApp (package-scoped here, as you proposed), the development-watch guard, their specs, both example applications and a short section in "Executing the Application Class". The finding-2 log line is here too, since it belongs with the member check. The loan return, the second-application refusal, the run-status change and the full doc page stay in #16456, which now carries this branch as a merge so it applies cleanly once this is merged up.

Could you review this one first? The specs here assert only what 8.0.x does: the parent holds the child's grailsApplication on loan while it runs, with no claim about what happens when the child closes.

@codecov

codecov Bot commented Oct 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 70.27027% with 33 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.9462%. Comparing base (626c81d) to head (b4b09c4).
⚠️ Report is 2 commits behind head on 8.0.x.

Files with missing lines Patch % Lines
...rc/main/groovy/grails/boot/GrailsAppBuilder.groovy 69.8113% 30 Missing and 2 partials ⚠️
...-core/src/main/groovy/grails/boot/GrailsApp.groovy 80.0000% 0 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@                Coverage Diff                 @@
##                8.0.x     #16462        +/-   ##
==================================================
+ Coverage     58.9311%   58.9462%   +0.0150%     
- Complexity      24441      24502        +61     
==================================================
  Files            2174       2174                
  Lines          107366     107476       +110     
  Branches        19557      19562         +5     
==================================================
+ Hits            63272      63353        +81     
- Misses          35231      35261        +30     
+ Partials         8863       8862         -1     
Files with missing lines Coverage Δ
...-core/src/main/groovy/grails/boot/GrailsApp.groovy 49.4681% <80.0000%> (+1.6420%) ⬆️
...rc/main/groovy/grails/boot/GrailsAppBuilder.groovy 70.0935% <69.8113%> (+70.0935%) ⬆️

... and 8 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@testlens-app

testlens-app Bot commented Oct 1, 2026

Copy link
Copy Markdown

✅ All tests passed ✅

🏷️ Commit: b4b09c4
▶️ Tests: 104085 executed
⚪️ Checks: 87/87 completed


Learn more about TestLens at testlens.app/docs.

@jdaugherty

Copy link
Copy Markdown
Contributor Author

This was split off the other PR that is already reviewed. Going to merge this and we can iterate if we need to.

@jdaugherty
jdaugherty merged commit 094c562 into 8.0.x Oct 2, 2026
90 checks passed
@jdaugherty
jdaugherty deleted the fix/grails-app-builder-hierarchies branch October 2, 2026 19:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant