in src/main/java/org/apache/maven/plugins/dependency/analyze/AnalyzeDepMgt.java [111:168]
private boolean checkDependencyManagement() throws MojoExecutionException {
boolean foundError = false;
getLog().info("Found Resolved Dependency/DependencyManagement mismatches:");
List<Dependency> depMgtDependencies = null;
DependencyManagement depMgt = project.getDependencyManagement();
if (depMgt != null) {
depMgtDependencies = depMgt.getDependencies();
}
if (depMgtDependencies != null && !depMgtDependencies.isEmpty()) {
// put all the dependencies from depMgt into a map for quick lookup
Map<String, Dependency> depMgtMap = new HashMap<>();
Map<String, Exclusion> exclusions = new HashMap<>();
for (Dependency depMgtDependency : depMgtDependencies) {
depMgtMap.put(depMgtDependency.getManagementKey(), depMgtDependency);
// now put all the exclusions into a map for quick lookup
exclusions.putAll(addExclusions(depMgtDependency.getExclusions()));
}
// get dependencies for the project (including transitive)
Set<Artifact> allDependencyArtifacts = new LinkedHashSet<>(project.getArtifacts());
// don't warn if a dependency that is directly listed overrides
// depMgt. That's ok.
if (this.ignoreDirect) {
getLog().info("\tIgnoring Direct Dependencies.");
Set<Artifact> directDependencies = project.getDependencyArtifacts();
allDependencyArtifacts.removeAll(directDependencies);
}
// log exclusion errors
List<Artifact> exclusionErrors = getExclusionErrors(exclusions, allDependencyArtifacts);
for (Artifact exclusion : exclusionErrors) {
getLog().info(getArtifactManagementKey(exclusion)
+ " was excluded in DepMgt, but version " + exclusion.getVersion()
+ " has been found in the dependency tree.");
foundError = true;
}
// find and log version mismatches
Map<Artifact, Dependency> mismatch = getMismatch(depMgtMap, allDependencyArtifacts);
for (Map.Entry<Artifact, Dependency> entry : mismatch.entrySet()) {
logMismatch(entry.getKey(), entry.getValue());
foundError = true;
}
if (!foundError) {
getLog().info("\tNone");
}
} else {
getLog().info("\tNothing in DepMgt.");
}
return foundError;
}