Repository navigation
Validate Grails BOM version properties against the Spring Boot BOM - #16428
Conversation
Several Grails BOM overrides of Spring Boot managed versions were declared under Grails-specific property names: jackson2.version, jackson3.version and neo4j-driver.version, where Spring Boot controls the same modules with jackson-2-bom.version, jackson-bom.version and neo4j-java-driver.version. Setting the property Spring Boot documents moved only the modules Grails does not pin, silently leaving a mixed Jackson or Neo4j driver classpath; the Spring Dependency Management end-to-end build had to copy the Jackson 3 version across by hand. The new bom-property-validator build plugin registers validateBomProperties on every BOM. It reads the POM the BOM publishes, walks spring-boot-dependencies and the BOMs it imports with Maven's own model, and fails when: - a version property the BOM owns is used by no published entry, - an override of a Spring Boot managed version uses a different property name than Spring Boot does (for a module Spring Boot manages through an imported BOM, the property that import uses), or - a pin repeats the version Spring Boot already manages. Fixing what it found: - rename jackson2.version -> jackson-2-bom.version, jackson3.version -> jackson-bom.version and neo4j-driver.version -> neo4j-java-driver.version - publish the platform BOMs the derived BOMs re-declare as constraints (groovy-bom, spock-bom, asset-pipeline-bom) with their property instead of a literal version, so overriding groovy.version moves them too - remove version keys no published entry used: kotlin.version, mockito.version, liquibase-hibernate5.version and the Gradle BOM's jquery.version - document the deliberate exceptions, each with its reason, in bomUnusedVersionExemptions, bomPropertyNameExemptions and bomRedundantVersionExemptions The task has its own opt-out, skipBomPropertyValidation, and runs in its own CI job like validateDependencyVersions. A -P opt-out given without a value now actually skips: Gradle passes it as an empty string, which the shared check parsed as false, so a bare -PskipDependencyValidation never took effect. The upgrade guide and the Grails 8 upgrade skill state that Grails BOMs now follow the upstream property names, and list the renames. Fixes #15737
sbglasius
left a comment
There was a problem hiding this comment.
Reviewed the BOM property validation changes and ran validateBomProperties on the branch; it passes. No blocking issues found.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## 8.0.x #16428 +/- ##
==================================================
+ Coverage 58.6019% 58.6036% +0.0017%
- Complexity 24306 24309 +3
==================================================
Files 2175 2175
Lines 107343 107345 +2
Branches 19567 19566 -1
==================================================
+ Hits 62905 62908 +3
- Misses 35580 35583 +3
+ Partials 8858 8854 -4
🚀 New features to boost your workflow:
|
codeconsole
left a comment
There was a problem hiding this comment.
Reviewed the BOM property renames, publishing changes, validator, tests, and CI wiring. All 58 focused tests passed (GradleUtilsSpec, ValidateBomPropertiesTaskSpec, GrailsBomPropertyValidatorPluginSpec, ValidateDependencyVersionsTaskSpec, and PropertyNameCalculatorSpec). One validator false negative was confirmed with an isolated Gradle fixture; details inline. Broad repository validation was left to PR CI.
|
|
||
| private String record(Dependency dependency, Map<String, String> bomProperties, String controllingProperty) { | ||
| String version = PomVersions.interpolate(dependency.version, bomProperties) | ||
| String key = PomVersions.key(dependency) |
There was a problem hiding this comment.
[P2] Interpolate dependency coordinates before indexing parent versions
MavenXpp3Reader leaves expressions in groupId and artifactId unresolved, but this key is stored without interpolation. This already affects BOMs imported by Spring Boot 4.1.1: Kotlin, Brave, Zipkin Reporter, and Querydsl declare managed dependencies with <groupId>${project.groupId}</groupId>. Their entries are indexed as ${project.groupId}:kotlin-stdlib, for example, so a Grails pin for org.jetbrains.kotlin:kotlin-stdlib never matches parentVersions and silently bypasses both the property-name and redundant-version checks.
I reproduced this through validateBomProperties using a local parent BOM managing ${project.groupId}:lib at ${lib.version}=1.0 and a published constraint for test:lib:1.0 under ${wrong.version}: validation succeeds. Replacing only the parent's group ID expression with literal test makes it correctly report both violations. Please interpolate the group/artifact coordinates against the effective POM properties before constructing the lookup key (and imported-BOM resolution coordinates), and cover this case in the functional spec.
There was a problem hiding this comment.
Confirmed against the Spring Boot 4.1.1 tree: kotlin-bom, brave-bom, zipkin-reporter-bom and querydsl-bom write their own group as ${project.groupId}. Fixed in 8cfecb0: PomVersions.key now interpolates the group and artifact IDs against the POM's effective properties, both for the lookup key and for the coordinates an imported BOM is resolved with.
The walk also now fails the task, naming the entry and the BOM, when it cannot resolve a parent entry's coordinates or version, instead of skipping it - that silent skip is what hid this. All 1963 entries across the 48 BOMs Spring Boot 4.1.1 pulls in resolve, so nothing fails today.
ValidateBomPropertiesTaskSpec covers it: the fixture's parent BOM now imports its family BOM as ${project.groupId}:family-bom, the family BOM manages ${project.groupId}:family-api, and a pin of test:family-api under the wrong property at the parent's version reports both violations. Separate features cover the published POM's own coordinates and an unresolvable parent entry. The same gap in the application-side BomManagedVersions is fixed too.
|
The requested change to interpolate dependency coordinates before indexing parent versions is already addressed by the logic in build-logic/docs-core/src/main/groovy/org/apache/grails/gradle/tasks/bom/PropertyNameCalculator.groovy |
codeconsole
left a comment
There was a problem hiding this comment.
Requesting changes for the confirmed validator false negative described in the inline review: parent BOM dependency coordinates containing property references are indexed without interpolation, allowing incorrect property names and redundant pins to bypass validation. Please interpolate those coordinates and add a functional regression test. All 58 focused tests passed, but the isolated reproducer demonstrates this uncovered case.
matrei
left a comment
There was a problem hiding this comment.
Reviewed at head d199bb475b. The base is 8.0.x at aa0b6c49e3, which is also the merge-base, so the PR is up to date and merges cleanly.
What I ran locally:
build-logic::build-logic:testand:grails-docs-core:testwithcleanTest --no-build-cache. All 249 plugin tests and 50 docs-core tests pass, includingValidateBomPropertiesTaskSpec(20),GradleUtilsSpec(22),ValidateDependencyVersionsTaskSpec(6),GrailsBomPropertyValidatorPluginSpec(3) andPropertyNameCalculatorSpec(7)../gradlew validateBomPropertiesat the root (all five BOMs) and ingrails-gradle(grails-gradle-bom) passes.- The check fails on the real BOMs when it should. In
dependencies.gradleI put backjackson3.versionandneo4j-driver.version, re-addedkotlin.versionandmockito.version, and setlogback.versionto Boot's1.5.38.grails-base-bomthen reported the two orphaned keys,${jackson3.version} should be ${jackson-bom.version}fortools.jackson.core:jackson-core/-databind, andlogback.version = 1.5.38as redundant.grails-neo4j-bomalso reported${neo4j-driver.version} should be ${neo4j-java-driver.version}.
Findings
1. ${project.groupId} coordinates: I agree with @codeconsole, and the Gradle plugin has the same gap
I reproduced @codeconsole's finding. Given a parent BOM that manages ${project.groupId}:lib at ${lib.version}, ParentBomVersions.resolve records the key as ${project.groupId}:lib, so a Grails pin of test:lib never matches it. The key is built from the raw groupId at ParentBomVersions.groovy:109, and the import coordinates at :102 have the same problem. In Spring Boot 4.1.1 this affects most of four imported BOMs:
| Imported BOM | Entries written as ${project.groupId} |
|---|---|
kotlin-bom 2.3.21 |
23 of 25 |
brave-bom 6.3.1 |
39 of 43 |
zipkin-reporter-bom 3.5.3 |
11 of 15 |
querydsl-bom 5.1.0 |
22 of 23 |
None of the published Grails BOMs pin a module from these families today, so nothing slips through yet. The fix is small, though, and a validator should not let these through, so I'd fix it in this PR. PomVersions.properties already provides project.groupId, so interpolating groupId/artifactId against bomProperties before building the key is enough.
BomManagedVersions in grails-gradle-plugins, the resolver behind the bom-property-overrides plugin that applications use, has the same gap at BomManagedVersions.groovy:452, and it matters more there. With the same fixture and ext['lib.version'] = '2.0', BomManagedVersions.resolve returns:
[${project.groupId}:lib:2.0, test:other:2.0]
The literal test:other entry is overridden. The ${project.groupId} entry becomes a strict constraint on a coordinate no module has, so it changes nothing. In a Grails 8 application, kotlin.version=… in gradle.properties therefore moves only 2 of the 25 Kotlin modules, and kotlin-stdlib isn't one of them. The same goes for brave.version, zipkin-reporter.version and querydsl.version. The Gradle plugin bug predates this PR. But the upgrade note this PR adds says that "the property names in the Spring Boot documentation work unchanged in a Grails build" (upgrading80x.adoc:567), and for these four families they currently don't. Either fix BomManagedVersions the same way here, or open an issue for it and soften that sentence until it is fixed.
The two resolvers now duplicate the same Maven walk (own entries before imports, parent-chain properties, interpolation), and this bug shows they can drift apart. I understand why build-logic can't depend on grails-gradle-plugins. It would still help for each class to reference the other in its Javadoc, so a fix to one gets made in the other.
2. The rename table should cover Spring Boot 3's jackson-bom.version
In Spring Boot 3.5 (Grails 7), jackson-bom.version is the Jackson 2 property: spring-boot-dependencies-3.5.x imports com.fasterxml.jackson:jackson-bom:${jackson-bom.version} (2.19.2 in 3.5.5). In Spring Boot 4 it selects tools.jackson:jackson-bom, and Jackson 2 moved to jackson-2-bom.version. A Grails 7 build that followed the Spring Boot docs may well have jackson-bom.version=2.x in gradle.properties.
With this PR that value now also reaches the two Jackson 3 modules grails-bom pins itself (dependencies.gradle:202-203). BomManagedVersions resolves every ${...} against the project's properties first (BomManagedVersions.groovy:450), so the override becomes a strict constraint on tools.jackson.core:jackson-core:2.x, a version that does not exist. On 8.0.x today the same setting is silently dropped: the tools.jackson:jackson-bom:2.x import fails to resolve and is only logged at INFO (BomManagedVersions.groovy:378). I worked this out from the code rather than running it in an app.
Failing the build is arguably better than ignoring the setting, but the Could not find tools.jackson.core:jackson-core:2.19.2 error doesn't tell anyone to rename the property. upgrading80x.adoc already has a Grails 7 → Grails 8 table right here (line 572), so a row there would cover it:
| `jackson-bom.version` (Spring Boot 3's name for Jackson 2)
| `jackson-2-bom.version`. In Grails 8, `jackson-bom.version` sets Jackson 3, so a 2.x value there makes the build fail.
The skill table (grails-8-upgrade/SKILL.md:81) would need the same row.
3. The advice for a module the parent writes literally can't be followed
When Spring Boot writes a module's version literally (all of its own org.springframework.boot:* entries), parentImportProperty (ValidateBomPropertiesTask.groovy:121-136) reports a Grails override as ${lib-literal.version} should be ${spring-boot.version} and says to rename the version key. That fix doesn't work. Writing the pin as ${spring-boot.version} gives it Boot's version, and then the redundancy rule flags it. The only real options are to drop the pin or exempt it. Nothing hits this today, and the spec encodes the current wording (ValidateBomPropertiesTaskSpec.groovy:193). A separate message for this case would save the next person some confusion, e.g.:
org.springframework.boot:spring-boot-foois managed at a literal version by the parent BOM and only moves with${spring-boot.version}. Drop the pin, or add a documented exemption.
Verified as correct
- The renamed properties match Spring Boot 4.1.1.
spring-boot-dependencies-4.1.1.pomdeclaresjackson-2-bom.version(2.21.5),jackson-bom.version(3.1.5),neo4j-java-driver.version,kotlin.version,mockito.version(5.23.0, the value the removed key held),graphql-java.version(25.0) andgroovy.version. The publishedgrails-base-bomPOM now writesjackson-core/jackson-databindas${jackson-2-bom.version}and${jackson-bom.version}. - One property moves both BOMs.
BomManagedVersionsapplies the project's properties to every BOM in the tree before each BOM's own<properties>, so the claim ingradleDependencies.adocand the upgrade note holds for Jackson and the Neo4j driver (for the four families in finding 1, see there). Maven consumers are no worse off: grails-bom's<jackson-bom.version>does not leak into Spring Boot's import scope, the same as before. - No leftover references to
jackson2.version,jackson3.version, thejackson2-*/jackson3-*map keys,neo4j-driver.version,kotlin.version,mockito.versionorliquibase-hibernate5.versionin build scripts, docs or skills. The upgrade guide'sjquery.version=3.7.1example still works, because only the Gradle BOM's copy ofjquery.versionwas removed.liquibase-hibernate.versionis the Grails 7 name too, so dropping the orphanedliquibase-hibernate5.versionneeds no rename row. - The parent walk matches Maven precedence (apart from finding 1). A BOM's own entries are recorded before its imports, and imports are walked depth first.
ParentBomVersionstakes only properties, not<dependencyManagement>, from a POM's<parent>. None of the BOMsspring-boot-dependencies4.1.1 imports has a parent that manages dependencies, so nothing is missed there today. - Derived BOMs get the right property. The
PropertyNameCalculatorchange gives the re-declaredgroovy-bom/spock-bom/asset-pipeline-bomconstraints${groovy.version}etc. instead of a literal, and the new spec pins the precedence (a plain definition wins over a platform one). - The
isOptedOutfix is real. A bare-PskipDependencyValidationarrives as"", whichBoolean.parseBooleanturned intofalse, so it never skipped, although the gradle-developer skill already said it did. It now skips, andValidateDependencyVersionsTaskSpeccovers the bare,=true,=falseandextforms. - CI. The new job uses
actions/*full tags and the samegradle/actions/setup-gradleSHA as the existing jobs.Validate BOM Propertiespasses on the PR. No@authortags in the new files.
| ExtractedDependencyConstraint calculate(String groupId, String artifactId, String version, boolean isPlatform) { | ||
| // a derived BOM re-declares the platforms it imports as plain constraints, which must carry | ||
| // the same property as the import so that overriding it moves both | ||
| String coordinates = "$groupId:$artifactId:$version" as String |
There was a problem hiding this comment.
There is no need to explicitly coerce (as String) as the variable is already typed and will be implicitly coerced.
The Kotlin, Brave, Zipkin Reporter and Querydsl BOMs that Spring Boot 4.1.1
imports write their own group as ${project.groupId}. Both BOM walkers keyed
those entries by the raw expression, so no real module ever matched them:
- validateBomProperties never checked a Grails pin of one of those modules
against Spring Boot's property name or version
- the bom-property-overrides plugin applications use turned an override such
as kotlin.version into a strict constraint on a module named
${project.groupId}:kotlin-stdlib, so it moved 2 of the 25 Kotlin modules
Group and artifact IDs are now interpolated from the BOM's own properties and
the Maven built-ins, for managed entries and imported BOMs alike. A project
property still overrides only versions, never which module an entry manages.
validateBomProperties now fails, naming the entry and the BOM, when it cannot
resolve a parent BOM entry, instead of silently leaving it unchecked. A pin of a
version the parent writes literally is reported on its own: only the property
the parent is imported with moves it, so there is no rename to suggest - drop
the pin or exempt it.
The upgrade guide and the Grails 8 upgrade skill add Spring Boot 3's
jackson-bom.version, which selected Jackson 2, to the rename table: in Grails 8
it selects Jackson 3.
jdaugherty
left a comment
There was a problem hiding this comment.
@matrei thanks for the thorough review. All three findings are addressed in 8cfecb0:
${project.groupId}coordinates - fixed in both walkers.BomManagedVersionsnow interpolates an entry's group and artifact IDs, for managed entries and imported BOMs alike, from the BOM's own properties only: a project property overrides versions, never which module an entry manages. Thebom-override-resolutionfixture now writes both a managed module and the imported BOM as${project.groupId}, andBomOverrideResolutionFunctionalSpecasserts that the override reachesorg.example:groupliband thatchild-bomis still re-imported. With that, the upgrade note's sentence about Spring Boot property names holds for Kotlin, Brave, Zipkin Reporter and Querydsl too, so I kept it. The two walkers now reference each other. InBomManagedVersionsthe note sits on the walk itself rather than in the class Javadoc, since that class is published andParentBomVersionsis not.- Spring Boot 3's
jackson-bom.version- added the row to the rename table inupgrading80x.adocand to the Grails 8 upgrade skill. - Versions the parent writes literally - a pin of one is now reported in its own group,
${foo.version}, where only ${spring-boot.version} moves the parent's version, with "remove the pin and inherit the parent BOM's version, or add a documented exemption" instead of the rename advice.
The as String you flagged is gone as well.
@codeconsole the false negative is fixed; details in your thread.
Verified locally: build-logic (302 tests), grails-gradle-plugins (313 tests and codeStyle), and validateBomProperties on all five root BOMs and grails-gradle-bom.
|
|
||
| private String record(Dependency dependency, Map<String, String> bomProperties, String controllingProperty) { | ||
| String version = PomVersions.interpolate(dependency.version, bomProperties) | ||
| String key = PomVersions.key(dependency) |
There was a problem hiding this comment.
Confirmed against the Spring Boot 4.1.1 tree: kotlin-bom, brave-bom, zipkin-reporter-bom and querydsl-bom write their own group as ${project.groupId}. Fixed in 8cfecb0: PomVersions.key now interpolates the group and artifact IDs against the POM's effective properties, both for the lookup key and for the coordinates an imported BOM is resolved with.
The walk also now fails the task, naming the entry and the BOM, when it cannot resolve a parent entry's coordinates or version, instead of skipping it - that silent skip is what hid this. All 1963 entries across the 48 BOMs Spring Boot 4.1.1 pulls in resolve, so nothing fails today.
ValidateBomPropertiesTaskSpec covers it: the fixture's parent BOM now imports its family BOM as ${project.groupId}:family-bom, the family BOM manages ${project.groupId}:family-api, and a pin of test:family-api under the wrong property at the parent's version reports both violations. Separate features cover the published POM's own coordinates and an unresolvable parent entry. The same gap in the application-side BomManagedVersions is fixed too.
| ExtractedDependencyConstraint calculate(String groupId, String artifactId, String version, boolean isPlatform) { | ||
| // a derived BOM re-declares the platforms it imports as plain constraints, which must carry | ||
| // the same property as the import so that overriding it moves both | ||
| String coordinates = "$groupId:$artifactId:$version" as String |
codeconsole
left a comment
There was a problem hiding this comment.
Reviewed the follow-up changes in 8cfecb0. The coordinate interpolation fix addresses my previous request for changes, including imported BOM coordinates and the application-side BOM override resolver. The added functional coverage exercises the reported case. I reran my original isolated reproducer: it now correctly reports both the misnamed property and redundant pin. All 40 focused tests passed across ValidateBomPropertiesTaskSpec, GrailsBomPropertyValidatorPluginSpec, BomManagedVersionsSpec, BomOverrideResolutionFunctionalSpec, BomPropertyOverridesPluginSpec, and BomPropertyOverridesPluginFunctionalSpec. No new actionable findings in the follow-up diff. Broad repository validation remains with PR CI.
✅ All tests passed ✅🏷️ Commit: 8cfecb0 Learn more about TestLens at testlens.app/docs. |
Fixes #15737
Why this matters
A Grails BOM that overrides a version Spring Boot also manages has to declare that override under Spring Boot's property name. If the names differ, setting a version property gives an incorrect configuration without any error: part of the dependency family moves and the rest does not.
That was the case on
8.0.x. Several overrides used Grails-specific names for modules Spring Boot controls under a different property:jackson2.versionjackson-2-bom.versionjackson3.versionjackson-bom.versionneo4j-driver.version(grails-neo4j-bom)neo4j-java-driver.versionFor example, an application following the Spring Boot documentation sets
jackson-bom.version=3.1.7. Spring Boot's importedtools.jackson:jackson-bommoves every Jackson 3 module to 3.1.7. Butgrails-bompinsjackson-coreandjackson-databinddirectly underjackson3.version, and a BOM's own entries win over the ones it imports. So those two stay at 3.1.6, and the application runs on a mixed Jackson 3 classpath without any warning. Settingjackson3.versioninstead has the opposite problem: it moves only the two pinned modules. The same applies to the Neo4j driver. The Spring Dependency Management end-to-end build already had to copy the Jackson 3 version from one property to the other by hand to stay consistent.Nothing in the build caught this, because
validateDependencyVersionsonly compares resolved versions and never looks at property names. The same gap let dead and redundant entries pile up:kotlin.versionandmockito.versionwere orphaned by a merge and never reached a published POM. Kotlin looked pinned below Spring Boot's version, but setting it did nothing.liquibase-hibernate5.versionand the Gradle BOM'sjquery.versionwere used by no published entry.groovy-bom,spock-bomandasset-pipeline-bomas constraints so thatenforcedPlatformconsumers get them, but published them with literal versions. Overridinggroovy.versiondid not move those constraints.What this adds
A new build plugin,
org.apache.grails.buildsrc.bom-property-validator, registersvalidateBomPropertieson every BOM (grails-base-bom,grails-bom,grails-hibernate5-bom,grails-hibernate7-bom,grails-neo4j-bomandgrails-gradle-bom). It reads the POM each BOM publishes, walksspring-boot-dependenciesand the BOMs it imports using Maven's own model (MavenXpp3Reader), and fails when:jackson-bom.versionfor all oftools.jackson:jackson-bom.It is modelled on
validateDependencyVersions:checkorbuild.grails-gradle-bom), and the release workflow runs it as a separate step.-PskipBomPropertyValidation/ext.skipBomPropertyValidation = true, which is separate fromskipDependencyValidation.Fixes it drove
Renamed
jackson2.version→jackson-2-bom.version,jackson3.version→jackson-bom.versionandneo4j-driver.version→neo4j-java-driver.version, along with the dependency keys that must prefix them.Removed
kotlin.version,mockito.version,liquibase-hibernate5.versionand the Gradle BOM'sjquery.version.PropertyNameCalculatornow gives a platform BOM that a derived BOM re-declares as a constraint the same property as its import.Documented deliberate exceptions in
dependencies.gradle, each with its reason:bomPropertyNameExemptionsjackson2-annotations.versionjackson-2-bom.versionbomPropertyNameExemptionsgradle-groovy.versiongroovy.versionwith the application's Groovy 5bomRedundantVersionExemptionsgraphql-java.versiongraphql-java-extended-scalarsbomUnusedVersionExemptionsmaven-model.versionFixed the shared skip-property check: Gradle passes a
-Pproperty given without a value as an empty string, which was parsed asfalse, so a bare-PskipDependencyValidationnever actually skipped anything.User-facing changes
The upgrade guide (section 14) and the Grails 8 upgrade skill now state that Grails BOMs follow the upstream BOM property names. They note that an override under a name no BOM declares is silently ignored, and list the renames:
jackson.version→jackson-2-bom.version(Jackson 3, the default, usesjackson-bom.version)jackson2.version,jackson3.versionandneo4j-driver.version→jackson-2-bom.version,jackson-bom.versionandneo4j-java-driver.versionThe build guide's section on overriding managed versions also explains that one Spring Boot property now sets the version in both BOMs.
Verification
ValidateBomPropertiesTaskSpec(TestKit, against a local fake parent BOM with an imported BOM and a parent POM),ValidateDependencyVersionsTaskSpec,GrailsBomPropertyValidatorPluginSpecandPropertyNameCalculatorSpec, plus new cases inGradleUtilsSpec. All build-logic tests pass.validateDependencyVersions(245 tasks),validateBomProperties(all six BOMs, includinggrails-gradle-bom) andvalidateActionspass.