From d6609276fcbc930df35639b2ae8bba4b92f0a230 Mon Sep 17 00:00:00 2001 From: Hitesh Date: Fri, 3 Jul 2026 19:00:24 +0530 Subject: [PATCH] Fix BOM version resolution for sibling modules in dependencyManagement --- .../maven/impl/model/DefaultModelBuilder.java | 74 ++++++++++++++----- 1 file changed, 57 insertions(+), 17 deletions(-) diff --git a/impl/maven-impl/src/main/java/org/apache/maven/impl/model/DefaultModelBuilder.java b/impl/maven-impl/src/main/java/org/apache/maven/impl/model/DefaultModelBuilder.java index 205b9eda93c2..69157362ed6d 100644 --- a/impl/maven-impl/src/main/java/org/apache/maven/impl/model/DefaultModelBuilder.java +++ b/impl/maven-impl/src/main/java/org/apache/maven/impl/model/DefaultModelBuilder.java @@ -611,28 +611,68 @@ public void mergeRepositories(Model model, boolean replace) { // Infer inner reactor dependencies version // Model transformFileToRaw(Model model) { - if (model.getDependencies().isEmpty()) { - return model; - } - List newDeps = new ArrayList<>(model.getDependencies().size()); boolean changed = false; - for (Dependency dep : model.getDependencies()) { - Dependency newDep = null; - if (dep.getVersion() == null) { - newDep = inferDependencyVersion(model, dep); - if (newDep != null) { - changed = true; + + List newDeps = null; + if (!model.getDependencies().isEmpty()) { + newDeps = new ArrayList<>(model.getDependencies().size()); + for (Dependency dep : model.getDependencies()) { + Dependency newDep = null; + if (dep.getVersion() == null) { + newDep = inferDependencyVersion(model, dep); + if (newDep != null) { + changed = true; + } + } else if (dep.getGroupId() == null) { + // Handle missing groupId when version is present + newDep = inferDependencyGroupId(model, dep); + if (newDep != null) { + changed = true; + } } - } else if (dep.getGroupId() == null) { - // Handle missing groupId when version is present - newDep = inferDependencyGroupId(model, dep); - if (newDep != null) { - changed = true; + newDeps.add(newDep == null ? dep : newDep); + } + } + + DependencyManagement newMgmt = null; + if (model.getDependencyManagement() != null + && !model.getDependencyManagement().getDependencies().isEmpty()) { + List newMgmtDeps = new ArrayList<>( + model.getDependencyManagement().getDependencies().size()); + boolean mgmtChanged = false; + for (Dependency dep : model.getDependencyManagement().getDependencies()) { + Dependency newDep = null; + if (dep.getVersion() == null) { + newDep = inferDependencyVersion(model, dep); + if (newDep != null) { + mgmtChanged = true; + } + } else if (dep.getGroupId() == null) { + // Handle missing groupId when version is present + newDep = inferDependencyGroupId(model, dep); + if (newDep != null) { + mgmtChanged = true; + } } + newMgmtDeps.add(newDep == null ? dep : newDep); + } + if (mgmtChanged) { + newMgmt = model.getDependencyManagement().withDependencies(newMgmtDeps); + changed = true; + } + } + + if (changed) { + Model.Builder builder = Model.newBuilder(model); + if (newDeps != null) { + builder.dependencies(newDeps); } - newDeps.add(newDep == null ? dep : newDep); + if (newMgmt != null) { + builder.dependencyManagement(newMgmt); + } + return builder.build(); } - return changed ? model.withDependencies(newDeps) : model; + return model; } private Dependency inferDependencyVersion(Model model, Dependency dep) {