in src/main/java/org/apache/maven/plugins/shade/mojo/ShadeMojo.java [1252:1326]
public boolean updateExcludesInDeps(
MavenProject project, List<Dependency> dependencies, List<Dependency> transitiveDeps)
throws DependencyCollectionException {
CollectRequest collectRequest = new CollectRequest();
collectRequest.setRootArtifact(RepositoryUtils.toArtifact(project.getArtifact()));
collectRequest.setRepositories(project.getRemoteProjectRepositories());
collectRequest.setDependencies(project.getDependencies().stream()
.map(d -> RepositoryUtils.toDependency(
d, session.getRepositorySession().getArtifactTypeRegistry()))
.collect(Collectors.toList()));
if (project.getDependencyManagement() != null) {
collectRequest.setManagedDependencies(project.getDependencyManagement().getDependencies().stream()
.map(d -> RepositoryUtils.toDependency(
d, session.getRepositorySession().getArtifactTypeRegistry()))
.collect(Collectors.toList()));
}
CollectResult result = repositorySystem.collectDependencies(session.getRepositorySession(), collectRequest);
boolean modified = false;
if (result.getRoot() != null) {
for (DependencyNode n2 : result.getRoot().getChildren()) {
String artifactId2 = getId(RepositoryUtils.toArtifact(n2.getArtifact()));
for (DependencyNode n3 : n2.getChildren()) {
// stupid m-a Artifact that has no idea what it is: dependency or artifact?
Artifact artifact3 = RepositoryUtils.toArtifact(n3.getArtifact());
artifact3.setScope(n3.getDependency().getScope());
String artifactId3 = getId(artifact3);
// check if it really isn't in the list of original dependencies. Maven
// prior to 2.0.8 may grab versions from transients instead of
// from the direct deps in which case they would be marked included
// instead of OMITTED_FOR_DUPLICATE
// also, if not promoting the transitives, level 2's would be included
boolean found = false;
for (Dependency dep : transitiveDeps) {
if (getId(dep).equals(artifactId3)) {
found = true;
break;
}
}
// MSHADE-311: do not add exclusion for provided transitive dep
// note: MSHADE-31 introduced the exclusion logic for promoteTransitiveDependencies=true,
// but as of 3.2.1 promoteTransitiveDependencies has no effect for provided deps,
// which makes this fix even possible (see also MSHADE-181)
if (!found && !"provided".equals(artifact3.getScope())) {
getLog().debug(String.format(
"dependency %s (scope %s) not found in transitive dependencies",
artifactId3, artifact3.getScope()));
for (Dependency dep : dependencies) {
if (getId(dep).equals(artifactId2)) {
// MSHADE-413: First check whether the exclusion has already been added,
// because it's meaningless to add it more than once. Certain cases
// can end up adding the exclusion "forever" and cause an endless loop
// rewriting the whole dependency-reduced-pom.xml file.
if (!dependencyHasExclusion(dep, artifact3)) {
getLog().debug(String.format(
"Adding exclusion for dependency %s (scope %s) " + "to %s (scope %s)",
artifactId3, artifact3.getScope(), getId(dep), dep.getScope()));
Exclusion exclusion = new Exclusion();
exclusion.setArtifactId(artifact3.getArtifactId());
exclusion.setGroupId(artifact3.getGroupId());
dep.addExclusion(exclusion);
modified = true;
break;
}
}
}
}
}
}
}
return modified;
}