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..db79f5c464b5 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 @@ -995,6 +995,9 @@ void buildEffectiveModel(Collection importIds) throws ModelBuilderExcept // dependency management import resultModel = importDependencyManagement(resultModel, importIds); + // [MNG-8432] Re-interpolate the model so that properties imported from BOMs can be used + resultModel = interpolateModel(resultModel, request, this); + // dependency management injection resultModel = dependencyManagementInjector.injectManagement(resultModel, request, this); @@ -2029,6 +2032,9 @@ private Model importDependencyManagement(Model model, Collection importI List importMgmts = null; + // [MNG-8432] Collect properties from imported BOMs so they can be used in the importing project. + Map importedProperties = new LinkedHashMap<>(); + List deps = new ArrayList<>(depMgmt.getDependencies()); for (Iterator it = deps.iterator(); it.hasNext(); ) { Dependency dependency = it.next(); @@ -2040,14 +2046,22 @@ private Model importDependencyManagement(Model model, Collection importI it.remove(); - DependencyManagement importMgmt = loadDependencyManagement(dependency, importIds); + Model importModel = loadBomModel(dependency, importIds); - if (importMgmt != null) { - if (importMgmts == null) { - importMgmts = new ArrayList<>(); + if (importModel != null) { + DependencyManagement importMgmt = importModel.getDependencyManagement(); + if (importMgmt != null) { + if (importMgmts == null) { + importMgmts = new ArrayList<>(); + } + importMgmts.add(importMgmt); } - importMgmts.add(importMgmt); + // Import BOM properties with lower priority (don't override existing properties) + for (Map.Entry entry : + importModel.getProperties().entrySet()) { + importedProperties.putIfAbsent(entry.getKey(), entry.getValue()); + } } } @@ -2056,10 +2070,26 @@ private Model importDependencyManagement(Model model, Collection importI model = model.withDependencyManagement( model.getDependencyManagement().withDependencies(deps)); + // Merge imported BOM properties into the model (model's own properties take precedence) + if (!importedProperties.isEmpty()) { + Map mergedProperties = new LinkedHashMap<>(importedProperties); + mergedProperties.putAll(model.getProperties()); + model = model.withProperties(mergedProperties); + } + return dependencyManagementImporter.importManagement(model, importMgmts, request, this); } - private DependencyManagement loadDependencyManagement(Dependency dependency, Collection importIds) { + /** + * Loads the full BOM model for the given import dependency. + * Returns the complete model (including properties and dependency management) + * so that the caller can extract both dependency management and properties. + * + * @param dependency the import-scoped dependency pointing to the BOM + * @param importIds collection of currently importing model IDs for cycle detection + * @return the resolved BOM model, or {@code null} if resolution failed + */ + private Model loadBomModel(Dependency dependency, Collection importIds) { String groupId = dependency.getGroupId(); String artifactId = dependency.getArtifactId(); String version = dependency.getVersion(); @@ -2113,14 +2143,18 @@ private DependencyManagement loadDependencyManagement(Dependency dependency, Col null, IMPORT, () -> doLoadDependencyManagement(dependency, groupId, artifactId, version, importIds)); - DependencyManagement importMgmt = importModel != null ? importModel.getDependencyManagement() : null; + if (importModel == null) { + return null; + } + + DependencyManagement importMgmt = importModel.getDependencyManagement(); if (importMgmt == null) { importMgmt = DependencyManagement.newInstance(); } // [MNG-5600] Dependency management import should support exclusions. List exclusions = dependency.getExclusions(); - if (importMgmt != null && !exclusions.isEmpty()) { + if (!exclusions.isEmpty()) { // Dependency excluded from import. List dependencies = importMgmt.getDependencies().stream() .filter(candidate -> exclusions.stream().noneMatch(exclusion -> match(exclusion, candidate))) @@ -2129,7 +2163,7 @@ private DependencyManagement loadDependencyManagement(Dependency dependency, Col importMgmt = importMgmt.withDependencies(dependencies); } - return importMgmt; + return importModel.withDependencyManagement(importMgmt); } @SuppressWarnings("checkstyle:parameternumber")