in maven-resolver-util/src/main/java/org/eclipse/aether/util/graph/manager/AbstractDependencyManager.java [202:281]
public DependencyManagement manageDependency(Dependency dependency) {
requireNonNull(dependency, "dependency cannot be null");
DependencyManagement management = null;
Object key = new Key(dependency.getArtifact());
if (isApplied()) {
Holder<String> version = managedVersions.get(key);
// is managed locally by model builder
// apply only rules coming from "higher" levels
if (version != null && isApplicable(version)) {
management = new DependencyManagement();
management.setVersion(version.getValue());
}
Holder<String> scope = managedScopes.get(key);
// is managed locally by model builder
// apply only rules coming from "higher" levels
if (scope != null && isApplicable(scope)) {
if (management == null) {
management = new DependencyManagement();
}
management.setScope(scope.getValue());
if (systemDependencyScope != null
&& !systemDependencyScope.is(scope.getValue())
&& systemDependencyScope.getSystemPath(dependency.getArtifact()) != null) {
Map<String, String> properties =
new HashMap<>(dependency.getArtifact().getProperties());
systemDependencyScope.setSystemPath(properties, null);
management.setProperties(properties);
}
}
// system scope paths always applied to have them aligned
// (same artifact == same path) in whole graph
if (systemDependencyScope != null
&& (scope != null && systemDependencyScope.is(scope.getValue())
|| (scope == null && systemDependencyScope.is(dependency.getScope())))) {
Holder<String> localPath = managedLocalPaths.get(key);
if (localPath != null) {
if (management == null) {
management = new DependencyManagement();
}
Map<String, String> properties =
new HashMap<>(dependency.getArtifact().getProperties());
systemDependencyScope.setSystemPath(properties, localPath.getValue());
management.setProperties(properties);
}
}
// optional is not managed by model builder
// apply only rules coming from "higher" levels
Holder<Boolean> optional = managedOptionals.get(key);
if (optional != null && isApplicable(optional)) {
if (management == null) {
management = new DependencyManagement();
}
management.setOptional(optional.getValue());
}
}
// exclusions affect only downstream
// this will not "exclude" own dependency,
// is just added as additional information
// ModelBuilder does not merge exclusions (only applies if dependency does not have exclusion)
// so we merge it here even from same level
Collection<Holder<Collection<Exclusion>>> exclusions = managedExclusions.get(key);
if (exclusions != null) {
if (management == null) {
management = new DependencyManagement();
}
Collection<Exclusion> result = new LinkedHashSet<>(dependency.getExclusions());
for (Holder<Collection<Exclusion>> exclusion : exclusions) {
result.addAll(exclusion.getValue());
}
management.setExclusions(result);
}
return management;
}