Fix BOM version resolution for sibling modules in dependencyManagement#12416
Fix BOM version resolution for sibling modules in dependencyManagement#12416Hiteshsai007 wants to merge 5 commits into
Conversation
elharo
left a comment
There was a problem hiding this comment.
- Needs tests
- Needs a link to github issue
|
@elharo Thanks for the review! I've addressed both items:
All 13 tests in |
gnodet
left a comment
There was a problem hiding this comment.
Review: Fix BOM version resolution for sibling modules in dependencyManagement
The core fix is correct and well-targeted — transformFileToRaw was only processing model.getDependencies() and ignoring model.getDependencyManagement().getDependencies(), which is the root cause of issue #11147. The fix correctly extends the same inferDependencyVersion and inferDependencyGroupId logic to managed dependencies. The test demonstrates the fix works, and the test POM files are well-structured.
Minor observations
1. Unnecessary list copy when only dependencyManagement changes (low)
impl/maven-impl/src/main/java/org/apache/maven/impl/model/DefaultModelBuilder.java
When model.getDependencies() is non-empty (so newDeps is allocated) but only mgmtChanged flips changed to true, the code enters if (changed) and then if (newDeps != null) passes, calling builder.dependencies(newDeps) with an identical list. This is harmless but creates an unnecessary copy. Consider tracking a separate boolean depsChanged flag.
2. Duplicated loop logic (low)
The for-loop bodies for regular dependencies and dependencyManagement dependencies are near-identical, differing only in the source list, target list, and changed-flag variable. Consider extracting a helper method to reduce duplication — though this is minor with only two occurrences.
Overall this is a clean, well-scoped fix. CI should be triggered (rebase to master) to validate the full test suite.
This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.
Claude Code on behalf of Guillaume Nodet
Reviewed 3 PRs: apache#12416 (BOM version resolution fix), apache#12410 (path-traversal re-review), apache#11818 (@nullable annotations). 5 findings verified, 5 false positives dropped. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
dd646fb to
e0ba241
Compare
…d separately - Extract inferDependencies() helper method to deduplicate the near-identical for-loop bodies for regular dependencies and dependencyManagement dependencies - Track separate depsChanged/mgmtChanged booleans to avoid unnecessary list copy when only dependencyManagement changes
|
Thanks for the review @gnodet! Both suggestions have been addressed in the latest commit: 1. Unnecessary list copy fix: 2. Duplicated loop logic: The branch has also been rebased onto the latest |
gnodet
left a comment
There was a problem hiding this comment.
Re-review — New Commit
The latest commit (acbea96) cleanly addresses both concerns from the previous review:
- Unnecessary list copy — Fixed by tracking separate
depsChangedandmgmtChangedflags, sobuilder.dependencies(newDeps)is only called when regular dependencies actually changed. - Duplicated loop logic — Extracted into a private
inferDependencieshelper method with proper Javadoc. Clean and well-structured.
The core fix remains correct and well-scoped. The test follows existing conventions in DefaultModelBuilderTest and exercises the specific scenario from issue #11147.
Minor Observations
- The test asserts
assertNotNull(managedDep.getVersion())but does not check the specific expected version value — asserting"1.0-SNAPSHOT"would make failures more diagnosable. - elharo's earlier
CHANGES_REQUESTEDreviews (needs tests, needs issue URL) have both been addressed.
No CI checks are reported for this branch — a rebase may be needed to trigger CI. ✅
This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.
Claude Code on behalf of Guillaume Nodet
Re-reviewed PRs apache#12419, apache#12417, apache#12416 after new commits. - apache#12419: APPROVE (formatting fix only) - apache#12417: COMMENT (improved but still no tests, BOM filter bug) - apache#12416: APPROVE (prior concerns addressed) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Thanks for the review and the approval, @gnodet! I've just pushed a small follow-up commit to address your minor observations:
Waiting on the CI results now! |
gnodet
left a comment
There was a problem hiding this comment.
Re-review — Feedback Addressed
The new commit (d932300) addresses the observation from the previous review: the test now uses assertEquals("1.0-SNAPSHOT", managedDep.getVersion(), "Version should be inferred from the reactor sibling module") instead of assertNotNull(managedDep.getVersion()), making test failures more diagnosable. ✅
No other changes — PR remains clean.
This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.
Claude Code on behalf of Guillaume Nodet
Author addressed assertion feedback from previous review. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Description
This PR addresses, fixing a regression in Maven 4 where version and
groupIdinference were skipped for dependencies declared within the<dependencyManagement>section of a BOM-packaged project.Issue: #11147
How it works:
I updated the
transformFileToRawmethod withinDefaultModelBuilderto ensure thatmodel.getDependencyManagement().getDependencies()is processed with the sameinferDependencyVersionandinferDependencyGroupIdlogic that is already applied to direct dependencies (model.getDependencies()).Why this is necessary:
Previously, if a BOM subproject declared sibling reactor modules within its
<dependencyManagement>block but omitted the<version>tags (expecting them to be resolved from the reactor), the transformation to the raw model would skip them entirely. This resulted in the installed consumer POM missing the required version tags for those managed dependencies. This change ensures that the reactor versions are properly inherited and written to the consumer POM.Testing:
bom-examplereproducer provided in the issue, confirming that the resulting consumer POM now contains the correctly inferred versions.spotless:applyand successfully passed allmaven-implunit tests. Note: Due to the complexity of simulating a full multi-module reactor state directly withinDefaultModelBuilderTest, a standalone unit test for this specific code path was omitted in favor of the reproducer validation.Following this checklist to help us incorporate your
contribution quickly and easily:
Note that commits might be squashed by a maintainer on merge.
This may not always be possible but is a best-practice.
mvn verifyto make sure basic checks pass.A more thorough check will be performed on your pull request automatically.
If your pull request is about ~20 lines of code you don't need to sign an
Individual Contributor License Agreement if you are unsure
please ask on the developers list.
To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.