[MNG-5527] Honor BOM relocation during dependency management import - #13081
[MNG-5527] Honor BOM relocation during dependency management import#13081goutamadwant wants to merge 2 commits into
Conversation
Follow partial and chained BOM relocations in both model builders while preserving import precedence, exclusions, resolver-selected versions, and ordinary imported-model validation behavior. Detect relocation and mixed import cycles, retain coordination for ordinary cold imports, and avoid cyclic waits introduced by relocation traversal. Add focused compatibility and concurrency tests and a Core IT for the reported missing managed-version failure. Signed-off-by: goutamadwant <workwithgoutam@gmail.com>
| + dependency.getManagementKey() + " is missing.") | ||
| .setLocation(dependency.getLocation(""))); | ||
| continue; | ||
| DependencyManagement importMgmt = loadDependencyManagement(dependency, model, request, problems, importIds); |
There was a problem hiding this comment.
renamed the variables to use full names.
| } | ||
|
|
||
| continue; | ||
| @SuppressWarnings("checkstyle:methodlength") |
There was a problem hiding this comment.
maybe you should break this method up
| importRequest.setUserProperties(request.getUserProperties()); | ||
| importRequest.setLocationTracking(request.isLocationTracking()); | ||
| } | ||
| final ModelBuildingResult importResult; |
There was a problem hiding this comment.
move into the try block, don't split declaration and initialization
There was a problem hiding this comment.
Sure. Moved the declaration and initialization of importResult inside the try block, together with the result handling. Let me know if this is good now
gnodet
left a comment
There was a problem hiding this comment.
I reviewed the three comments from @elharo. Here's my assessment:
Comment 1 — "no abbreviations please" (line 1185, importMgmt)
importMgmt is not new to this PR — it already exists on master (along with depMgmt) in the same method. The PR merely moved this code into an extracted loadDependencyManagement method. While renaming abbreviations is a fine cleanup, it shouldn't be a blocker for this PR since it's pre-existing code. If there's a desire to rename these, it could be done as a separate cleanup across the file.
Comment 2 — "maybe you should break this method up" (line 1199, @SuppressWarnings("checkstyle:methodlength"))
The @SuppressWarnings("checkstyle:methodlength") was on master's importDependencyManagement before this PR. This PR already did break the method up: it extracted loadDependencyManagement out of importDependencyManagement, which went from ~160 lines down to ~15. The new method inherited the suppress annotation because the relocation-chain logic added more code. Further decomposition is possible (e.g., extracting the relocation handling) but this is already a significant improvement over master.
Comment 3 — "move into the try block, don't split declaration and initialization" (line 1303)
The final ModelBuildingResult importResult; pattern is carried verbatim from master (previously at the same indentation inside the loop). It's a pre-existing pattern, not introduced by this PR. That said, it's a trivial fix — the variable can be moved inside the try block:
try {
final ModelBuildingResult importResult = build(importRequest, importIds);
problems.addAll(importResult.getProblems());
importModel = importResult.getEffectiveModel();
} catch (ModelBuildingException e) {
problems.addAll(e.getProblems());
return null;
}This is a reasonable cleanup the contributor could apply.
Summary: All three comments point at pre-existing patterns that this PR carried over unchanged. Comment 3 is the only one with a concrete, actionable fix that's trivial to apply. The other two are either already addressed by the PR (method extraction) or out of scope (renaming existing abbreviations).
|
Maven 4 already has a relocation SPI: Also a relocation-only loop reports "dependencies of type=pom and with scope=import form a cycle" though one import is declared; |
|
Good observations @renechoi. Two distinct points here: 1. Relationship with These operate at different layers:
Before this PR, if a BOM declared Regarding 2. Error message wording for relocation-only cycles Valid point. When a cycle involves only relocation hops (no actual This review was generated by an AI agent, Hermès on behalf of @gnodet. |
Use a cycle diagnostic that covers imports and relocations in both model builders. Assert the complete message for ordinary, relocation-only, and mixed cycles. Extract imported-model resolution from compatibility dependency-management loading, expand the local variable names, and initialize the model-building result inside its try block. Signed-off-by: goutamadwant <workwithgoutam@gmail.com>
Yes, this fix is limited to distributionManagement relocations in imported BOMs. Imports use ModelResolver rather than the artifact-descriptor relocation SPI; extending maven.relocations.entries to BOM imports would be a separate change. Changed the diagnostic to “The import POMs form a cycle”, covering ordinary imports, relocations, and mixed cycles. Both model builders now assert the message and cycle path. @gnodet, could you approve the new CI run? |
gnodet
left a comment
There was a problem hiding this comment.
Second commit (a7b8f49) addresses all outstanding review feedback:
-
Variable renames —
depMgmt→dependencyManagement,importMgmt→importedManagement,importMgmts→importedManagements. Pre-existing abbreviations cleaned up per @elharo's request. -
Method extraction —
resolveImportModel()extracted fromloadDependencyManagement(), removing the@SuppressWarnings("checkstyle:methodlength"). The extraction is a pure refactoring: workspace-first resolution with early return, then fallback toModelResolver, same semantics as before with cleaner flow. -
Declaration inside try —
importResultis now declared and initialized inside the try block as requested. -
Cycle diagnostic — Message changed to
"The import POMs form a cycle: ..."in both model builders (compat and impl), covering relocations, imports, and mixed cycles. Concise and accurate regardless of whether the cycle involves relocation hops. -
New tests —
detectsImportCycle()in the compat builder test anddetectsDirectImportCycle()in the impl builder test, both asserting the updated cycle message.
CI status: all completed checks are green. The one failure (integration-tests (macos-latest, 17)) is an infrastructure issue — the "Set up JDK 17" step failed, not related to this PR. Remaining checks still in progress.
Changes look solid. @gnodet — this is ready for your review when CI completes.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
|
CI has been approved and is running. Status so far:
The second commit addresses all review feedback cleanly:
Looks good. I'll re-check once the remaining integration tests complete. This comment was generated by an AI agent, Hermès on behalf of @gnodet. |
Fixes #6804.
Follow BOM relocation chains in both model builders, including partial relocations. Preserve dependency-management precedence, import exclusions, and the modern resolver's selected version when resolving a range.
Report invalid relocation coordinates, missing relocation targets, and relocation/import cycles without changing ordinary imported-model validation behavior. Preserve sharing of ordinary in-flight imports while avoiding cyclic waits introduced by relocation traversal.
Validation:
The reported failure reproduces on untouched master and passes with the fix through both the CLI and the new Core IT.
All 39 focused relocation, compatibility, and concurrency tests pass.
mvn verifypasses: 3,152 unit tests, zero failures/errors, 16 skips, plus one reactor integration test.Full forked Core IT: 1,074 tests, three failing tests, 43 skips. MNG3955 and MNG4411 fail identically on untouched master. MavenITMvnupToolchainPluginStrategyTest passes after refreshing its previously modified generated fixture. MNG4590 and the new MNG5527 test pass in the full run.
This pull request addresses one issue without unrelated changes.
The description explains what changes, how, and why.
Commits have meaningful subjects and bodies.
Regression tests cover the behavioral changes; the reported case fails without the fix.
mvn verifypasses.The Core IT suite passes.
I hereby declare this contribution to be licenced under the Apache License Version 2.0, January 2004.
In any other case, please file an Apache Individual Contributor License Agreement.