Skip to content

Contribute the Grails BOM platform lazily so defaultDependencies keep firing - #16416

Merged
jdaugherty merged 4 commits into
8.0.xfrom
fix/bom-platform-default-dependencies
Sep 28, 2026
Merged

jdaugherty merged 4 commits into
8.0.xfrom
fix/bom-platform-default-dependencies

Conversation

@jdaugherty

@jdaugherty jdaugherty commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Problem

GrailsGradlePlugin.applyGrailsBom() added the selected Grails BOM as a platform() to every declarable configuration eagerly, from afterEvaluate. A platform is a declared dependency, and Gradle's defaultDependencies { } hooks only fire on a configuration that holds no dependencies at all (gradle/gradle#11209). Any configuration another plugin populates on demand therefore ended up holding only the BOM:

  • the core jacoco plugin's jacocoAgent / jacocoAnt never received org.jacoco:org.jacoco.agent / org.jacoco:org.jacoco.ant, so ./gradlew test failed with Expected configuration ':jacocoAgent' to contain exactly one file, however, it contains no files.
  • the plugin's own profile configuration lost its default org.apache.grails.profiles:<profile> dependency the same way (visible in the new fixture when run against the unfixed plugin: PROFILE_DEFAULT_DECLARED=false).

Fix

The platform is now contributed through Configuration.withDependencies instead of DependencyHandler.add. Gradle runs a configuration's dependency actions once, when its dependencies are first observed (resolution, publication, incoming.dependencies): defaultDependencies first, and only while the configuration is empty, then withDependencies. The defaults other plugins install therefore keep firing, and the BOM still lands on every declarable configuration - including ones created after afterEvaluate, since the registration goes through configurations.configureEach. Published POMs/module metadata are unaffected: Gradle's publishing component reads incoming.dependencies, which runs the actions.

Two places read declared dependencies eagerly in afterEvaluate and needed adapting:

  • bom-property-overrides auto-detects BOMs by scanning declared platforms. applyGrailsBom now registers the auto-applied BOM with the bomPropertyOverrides extension explicitly (respecting autoDetect = false), so property overrides keep working for the injected BOM.
  • validateMicronautBom accepted only a hand-declared enforcedPlatform on implementation. It now also accepts the case where implementation declares no Grails BOM by hand and the BOM selected for automatic application is a Micronaut variant (always contributed as enforcedPlatform).

The effective-BOM selection (hand-declared BOM wins over grails.bom, fail fast on more than one) moved into a shared effectiveGrailsBom() helper used by both callers.

Tests

grails-gradle/plugins TestKit coverage:

  • New bom-platform-default-dependencies fixture (POM-only local repository, nothing hits the network): a Grails app applying jacoco, a custom configuration populated through defaultDependencies, and a version-less dependency managed by the BOM. Asserts jacocoAgent, jacocoAnt, the custom configuration and the profile configuration all keep their defaults and receive the platform, and that the lazily contributed platform still manages versions. Fails against the unfixed plugin.
  • New bom-platform-micronaut fixture: the auto-applied Micronaut variant satisfies the enforcedPlatform validation and arrives as enforced-platform; opting out without declaring one by hand still fails the validation.
  • Existing bom-platform-basic / bom-platform-manual / auto-apply-bom-disabled fixtures now observe dependencies through resolvable configurations (incoming.dependencies), and the basic one asserts the platform is not declared before observation.

Docs: gradleDependencies.adoc and the Grails 8 upgrade notes describe the lazy contribution and its effect on defaultDependencies-populated configurations.

Verification

  • cd grails-gradle && ./gradlew :grails-gradle-plugins:codeStyle - clean.
  • cd grails-gradle && DO_NOT_CACHE_TESTS=1 ./gradlew :grails-gradle-plugins:test - 44 suites, 308 tests, 0 failures. The new default-dependencies feature fails against the unfixed plugin (JACOCO_AGENT_RESOLVED=[org.apache.grails:lazy-bom:1.0-lazy], PROFILE_DEFAULT_DECLARED=false).
  • ./gradlew rat from the root - 0 unknown licenses.
  • Root build smoke check against the composite-included plugin: jacoco applied to grails-test-examples/app1 with grails { bom = 'grails-bom' } forced on (the test examples normally opt out). :grails-test-examples-app1:dependencies --configuration jacocoAgent now lists org.jacoco:org.jacoco.agent:0.8.14 next to org.apache.grails:grails-bom -> project ':grails-bom', and the profile configuration declares org.apache.grails.profiles:web next to the BOM.

Fixes #16335

… firing

The Grails Gradle plugin injected the selected Grails BOM eagerly into every
declarable configuration from afterEvaluate. A platform counts as a declared
dependency, so Gradle's defaultDependencies hooks - which only fire on an
otherwise empty configuration - never ran for configurations other plugins
populate on demand. The jacoco plugin's jacocoAgent/jacocoAnt resolved to
the BOM alone and 'test' failed with "Expected configuration ':jacocoAgent'
to contain exactly one file"; the plugin's own 'profile' configuration lost
its default profile the same way.

The platform is now contributed through Configuration.withDependencies,
which Gradle runs after defaultDependencies when a configuration's
dependencies are first observed. The two eager readers of declared
dependencies are adapted: the auto-applied BOM is registered explicitly with
bom-property-overrides (its auto-detection scans declared platforms in
afterEvaluate), and the Micronaut enforcedPlatform validation accepts the
Micronaut variant selected for automatic application.

Fixes #16335
@jdaugherty jdaugherty added this to the grails:8.0.0-RC2 milestone Sep 28, 2026
@codecov

codecov Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 34 lines in your changes missing coverage. Please review.
✅ Project coverage is 57.8590%. Comparing base (c482791) to head (090bd52).
⚠️ Report is 161 commits behind head on 8.0.x.

Files with missing lines Patch % Lines
...rails/gradle/plugin/core/GrailsGradlePlugin.groovy 0.0000% 34 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@                Coverage Diff                 @@
##                8.0.x     #16416        +/-   ##
==================================================
- Coverage     57.8656%   57.8590%   -0.0066%     
- Complexity      22870      22871         +1     
==================================================
  Files            2137       2137                
  Lines          104677     104689        +12     
  Branches        18811      18815         +4     
==================================================
  Hits            60572      60572                
- Misses          35742      35755        +13     
+ Partials         8363       8362         -1     
Files with missing lines Coverage Δ
...rails/gradle/plugin/core/GrailsGradlePlugin.groovy 0.0000% <0.0000%> (ø)

... and 3 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.

@jdaugherty
jdaugherty marked this pull request as ready for review September 28, 2026 04:59
@testlens-app

This comment has been minimized.

@matrei matrei left a comment

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.

Thanks @jdaugherty. I reviewed head 5cefc3f2c5: the fix in 4839d8130d plus the merge of 8.0.x, which moves both builds to Gradle 9.8.0. The merge doesn't change any code this PR touches, so the review applies to 9.8.0 as it stands. Contributing the platform through withDependencies is the right fix: it covers jacocoAgent/jacocoAnt, our own profile configuration and any third-party configuration populated through defaultDependencies, not only jacoco. I have one small code change to ask for, and the rest is questions and nits.

Run locally:

What Result
grails-gradle on 9.8.0: DO_NOT_CACHE_TESTS=1 ./gradlew :grails-gradle-plugins:test --tests '*Bom*' --tests '*CliAutoDiscoverySpec' --rerun 8 specs, 29 tests, 0 failures (BomPlatformFunctionalSpec 5/5, BomCliMultiprojectRaceFunctionalSpec 1/1, CliAutoDiscoverySpec 8/8 including the new --warning-mode=fail feature)
The BOM fixtures again with --warning-mode=all no deprecation from the plugin. The only warnings are older project.plugins.findPlugin(...) calls inside doLast in the fixtures, which this PR doesn't touch
Scratch build on Gradle 9.7.1 and 9.8.0, platform added via configureEach + withDependencies from afterEvaluate (java-library + maven-publish) same result on both versions, details below

The new --warning-mode=fail feature only configures tasks and doesn't resolve anything, so it never runs the withDependencies action. That's why I also ran the BOM fixtures, which do resolve, with --warning-mode=all.

What the scratch build showed:

  • Publication is unaffected. generatePomFileForMavenPublication still writes the BOM as a <dependencyManagement> import, and module.json still lists it with org.gradle.category: platform for both apiElements and runtimeElements. That confirms the claim in the description.
  • Observing a configuration before the afterEvaluate does not lose the platform. When the build script reads compileClasspath.incoming.dependencies at configuration time, the withDependencies action registered later still runs when the configuration is resolved.
  • A late-created configuration can break the build. See point 1.

1. canBeDeclared is checked before the configuration's role is final

GrailsGradlePlugin.groovy:600: the configureEach action checks configuration.canBeDeclared when the configuration is added to the container. For configurations.create(name) { ... }, Gradle adds the configuration before it runs the configure closure. So if a plugin or build creates a configuration after the Grails afterEvaluate has run and turns off canBeDeclared in the closure, the action is attached while the configuration is still declarable. Resolving the configuration then fails:

afterEvaluate {   // registered after the Grails plugin's afterEvaluate
    configurations.create('late') { canBeDeclared = false; canBeConsumed = false; canBeResolved = true }
}
// resolving 'late':
// > Dependencies can not be declared against the `late` configuration.

Before this PR, configurations created after the afterEvaluate were never touched, so this is new. Setting the role in the create closure is still supported: 9.8.0 prints no deprecation warning for it. configurations.register(...) and resolvable(...) / consumable(...) / dependencyScope(...) are fine, because their role is set before configureEach runs (checked with register('reg') { canBeDeclared = false }). The case is narrow, but the failure is a hard error in someone else's configuration, and the fix is one line: check again inside the action, where the role is final:

configuration.withDependencies { DependencySet dependencies ->
    if (!configuration.canBeDeclared || declaresGrailsBom(dependencies)) {
        return
    }
    ...
}

With that check added, the scratch build resolves late without error on 9.8.0. A variant of the bom-platform-default-dependencies fixture that creates such a configuration in a later afterEvaluate would cover it.

2. Should jacocoAgent / jacocoAnt receive the Grails BOM at all?

With this change, the jacoco configurations get their defaults back and also receive the Grails BOM (the new test asserts JACOCO_AGENT_RESOLVED=[…lazy-bom…, org.jacoco.agent…]). isExcludedFromBomPlatform already excludes checkstyle, codenarc, pmd, spotbugs and spotbugsPlugins. Commit 5e89656e46 gives the reason: tool classpaths should not receive platform() constraints, because these take part in conflict resolution and can upgrade the tools' transitive dependencies. jacocoAnt is the same kind of classpath. org.jacoco.core depends on org.ow2.asm:asm*, and grails-bom manages ASM. Today that is probably harmless, but it is the case the exclusion list exists for. Should jacocoAgent and jacocoAnt be added to the list? The lazy contribution is still needed for profile and for third-party configurations. For jacoco, the test would then check that the defaults resolve without the BOM.

3. Upgrade notes: the BOM is no longer visible as a declared dependency

The fixture changes show a behaviour change that user builds can run into as well. configurations.implementation.dependencies / allDependencies no longer contain the Grails BOM until something resolves or observes the configuration. The three existing fixtures had to switch to incoming.dependencies because of this. The same applies to any third-party plugin that scans declared platforms in afterEvaluate, which is exactly what bom-property-overrides did and why it now needs the explicit overrides.bom(...) registration. I'd add a sentence to the upgrading80x.adoc paragraph, for example: The platform is therefore not visible in a configuration's declared dependencies / allDependencies; build logic that looks for it should inspect incoming.dependencies or the resolution result instead.

Nits

  • bom-platform-default-dependencies/build.gradle:64: JACOCO_AGENT_HAS_BOM is printed but never asserted. It is already implied by JACOCO_AGENT_RESOLVED, so either assert it or drop the line.
  • The autoDetect = false branch of the new overrides.bom(...) registration (GrailsGradlePlugin.groovy:621) has no test. BomCliMultiprojectRaceFunctionalSpec covers the autoDetect = true path with an auto-applied BOM. The case where a property override is not applied because autoDetect = false is not covered.
  • gradleDependencies.adoc: "when a configuration's dependencies are first resolved" is slightly narrower than the code comment's "observed" (publication, incoming.dependencies). For users, "resolved" is probably the more useful word, so I'm fine either way.

Verified as correct

  • effectiveGrailsBom() is a straight extraction. validateMicronautBom runs after applyGrailsBom's afterEvaluate, so the "more than one Grails BOM" failure is still reported from the same place.
  • The new Micronaut acceptance clause only applies when implementation declares no Grails BOM by hand. So a hand-declared non-enforced platform(grails-micronaut-bom) still fails, and so does grails.bom = null without a hand-declared BOM (covered by the new negative test).
  • ENFORCED_PLATFORM_BOMS has the same three names as the removed local validMicronautBoms set. category.name is equivalent to the old toString() comparison.
  • The overrides.bom(...) call runs in an afterEvaluate registered before BomPropertyOverridesPlugin is applied, so it lands before the plugin reads extension.boms. When a BOM is also declared by hand at a different version, both coordinates are processed. That matches the old behaviour, where the injected copy on sibling configurations was auto-detected too.
  • The strict override constraints from BomManagedVersions.applyTo are dependency constraints, not dependencies, so they do not suppress defaultDependencies either.

Recheck late-created configuration roles before adding dependencies and exclude JaCoCo tool configurations from the application BOM. Cover automatic and explicit BOM property-override registration, and document lazy dependency observation.
@jdaugherty

Copy link
Copy Markdown
Contributor Author

@matrei, addressed the requested change and the remaining feedback in 0a40d94.

  • Late configuration roles: withDependencies now rechecks canBeDeclared before adding the platform. The regression fixture creates a non-declarable configuration in a later afterEvaluate callback and resolves it under --warning-mode=fail. It reproduced the reported exception before the fix and now passes. A companion assertion verifies that a late-created declarable configuration still receives its default dependency and the BOM.
  • JaCoCo tool classpaths: agreed; both jacocoAgent and jacocoAnt are now excluded from automatic application-platform injection, like the other tool configurations. The fixture verifies that their defaults resolve without the BOM and explicitly asserts both BOM-presence diagnostics are false. The profile and custom defaultDependencies coverage remains in place.
  • Property-override detection: added a three-case resolution test covering automatic detection enabled, disabled without explicit registration, and disabled with an explicitly registered BOM. Disabling detection leaves the platform in place but does not apply the property override unless the BOM is explicitly registered.
  • Documentation: the upgrade notes now explain that dependencies / allDependencies do not expose the auto-applied BOM until observation, and direct build logic to incoming.dependencies or the resolution result. Both guide sections now use “observed” and describe the tool-classpath exclusions.

Verification on Gradle 9.8.0 / JDK 21:

Check Result
Full grails-gradle-plugins suite 313 tests across 44 suites; zero failures or skips
Plugin dependency validation and aggregate violation reports Clean
Root aggregate tests 21,311 reported; zero failures/errors; 445 skipped
Root aggregate violation reports All four summaries clean
Apache RAT Zero unknown licenses after removing two ignored Neo4j runtime files generated by the tests

There are no inline review threads on this PR to resolve, so this response covers the feedback in the review body.

@jdaugherty
jdaugherty requested a review from matrei September 28, 2026 15:31

@matrei matrei left a comment

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.

Thanks @jdaugherty. Second round, at head 0a40d94fa1. All points from my previous review are addressed.

Run locally on Gradle 9.8.0:

What Result
DO_NOT_CACHE_TESTS=1 ./gradlew :grails-gradle-plugins:test --tests '*Bom*' --tests '*CliAutoDiscoverySpec' --rerun 8 specs, 33 tests, 0 failures (BomPlatformFunctionalSpec 9/9)
The same BomPlatformFunctionalSpec run with the new canBeDeclared check removed from the withDependencies action only "late-created configurations receive the platform only if their final role allows dependencies" fails, with Dependencies can not be declared against the `lateResolvable` configuration
  1. Late configuration roles: the check inside withDependencies is the fix I had in mind. The new feature fails without it and passes with it, as shown above. The lateDeclarable companion also covers the other side: a configuration created late with a declarable role still gets both its defaults and the platform.
  2. JaCoCo: jacocoAgent / jacocoAnt are now in isExcludedFromBomPlatform. The fixture asserts that the defaults resolve without the BOM and that both *_HAS_BOM values are false. profile and the custom defaultDependencies configuration still verify the lazy contribution.
  3. Upgrade notes: the new sentence about dependencies / allDependencies covers the behaviour change. Both guide sections now say "observed" and mention the tool-classpath exclusions.
  4. Nits: JACOCO_AGENT_HAS_BOM is asserted now. The autoDetect matrix covers all three cases, and the managed-lib.version property in the fixture BOM makes the override observable. The new gradleDependencies.adoc paragraph describes the autoDetect = false behaviour correctly.

Two small things, neither blocking:

  • GrailsGradlePlugin.groovy:597: after the edit, the comment block breaks mid-sentence ("Registering through configureEach also covers" on its own short line). Re-wrapping the last two lines would tidy it up.
  • FYI, and not caused by this PR: the property-override constraints still ignore the exclusion list. BomPropertyOverridesPlugin.groovy:165 applies them to every declarable configuration, jacocoAnt, checkstyle and the other tool classpaths included. So ext['asm.version'] = '…' would also force ASM strictly on those classpaths. The new doc sentence says the tool classpaths are excluded "so the application BOM does not change their transitive dependency versions", which is true for the platform but not for an explicit property override. That is arguably what a user who sets the property wants, and BomPropertyOverridesPlugin is BOM-agnostic and has no knowledge of the Grails exclusions. So I'd leave it for a follow-up, if anyone thinks it is worth changing at all.

Approving. CI was still running when I posted: 24 checks had passed, and the only failure was the cancelled "Release - Drafter" run, which is unrelated.

@jdaugherty
jdaugherty merged commit 60b42c9 into 8.0.x Sep 28, 2026
19 of 20 checks passed
@jdaugherty
jdaugherty deleted the fix/bom-platform-default-dependencies branch September 28, 2026 16:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Gradle plugin injects the Grails BOM into every configuration, defeating defaultDependencies (breaks core Gradle jacoco plugin)

2 participants