Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -995,6 +995,9 @@ void buildEffectiveModel(Collection<String> 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);

Expand Down Expand Up @@ -2029,6 +2032,9 @@ private Model importDependencyManagement(Model model, Collection<String> importI

List<DependencyManagement> importMgmts = null;

// [MNG-8432] Collect properties from imported BOMs so they can be used in the importing project.
Map<String, String> importedProperties = new LinkedHashMap<>();

List<Dependency> deps = new ArrayList<>(depMgmt.getDependencies());
for (Iterator<Dependency> it = deps.iterator(); it.hasNext(); ) {
Dependency dependency = it.next();
Expand All @@ -2040,14 +2046,22 @@ private Model importDependencyManagement(Model model, Collection<String> 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<String, String> entry :
importModel.getProperties().entrySet()) {
importedProperties.putIfAbsent(entry.getKey(), entry.getValue());
}
}
}

Expand All @@ -2056,10 +2070,26 @@ private Model importDependencyManagement(Model model, Collection<String> 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<String, String> 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<String> 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<String> importIds) {
String groupId = dependency.getGroupId();
String artifactId = dependency.getArtifactId();
String version = dependency.getVersion();
Expand Down Expand Up @@ -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<Exclusion> exclusions = dependency.getExclusions();
if (importMgmt != null && !exclusions.isEmpty()) {
if (!exclusions.isEmpty()) {
// Dependency excluded from import.
List<Dependency> dependencies = importMgmt.getDependencies().stream()
.filter(candidate -> exclusions.stream().noneMatch(exclusion -> match(exclusion, candidate)))
Expand All @@ -2129,7 +2163,7 @@ private DependencyManagement loadDependencyManagement(Dependency dependency, Col
importMgmt = importMgmt.withDependencies(dependencies);
}

return importMgmt;
return importModel.withDependencyManagement(importMgmt);
}

@SuppressWarnings("checkstyle:parameternumber")
Expand Down