private void createDependencyReducedPom()

in src/main/java/org/apache/maven/plugins/shade/mojo/ShadeMojo.java [1056:1121]


    private void createDependencyReducedPom(Set<String> artifactsToRemove)
            throws IOException, ProjectBuildingException, DependencyCollectionException {
        List<Dependency> transitiveDeps = new ArrayList<>();

        // NOTE: By using the getArtifacts() we get the completely evaluated artifacts
        // including the system scoped artifacts with expanded values of properties used.
        for (Artifact artifact : project.getArtifacts()) {
            if ("pom".equals(artifact.getType())) {
                // don't include pom type dependencies in dependency reduced pom
                continue;
            }

            // promote
            Dependency dep = createDependency(artifact);

            // we'll figure out the exclusions in a bit.
            transitiveDeps.add(dep);
        }

        Model model = project.getOriginalModel();

        // MSHADE-413: Must not use objects (for example `Model` or `Dependency`) that are "owned
        // by Maven" and being used by other projects/plugins. Modifying those will break the
        // correctness of the build - or cause an endless loop.
        List<Dependency> origDeps = new ArrayList<>();
        List<Dependency> source = promoteTransitiveDependencies ? transitiveDeps : project.getDependencies();
        for (Dependency d : source) {
            origDeps.add(d.clone());
        }
        model = model.clone();

        // MSHADE-185: We will remove all system scoped dependencies which usually
        // have some kind of property usage. At this time the properties within
        // such things are already evaluated.
        List<Dependency> originalDependencies = model.getDependencies();
        removeSystemScopedDependencies(artifactsToRemove, originalDependencies);

        List<Dependency> dependencies = new ArrayList<>();
        boolean modified = false;
        for (Dependency d : origDeps) {
            if (artifactsToRemove.contains(getId(d))) {
                if (keepDependenciesWithProvidedScope) {
                    if (!"provided".equals(d.getScope())) {
                        modified = true;
                        d.setScope("provided");
                    }
                } else {
                    modified = true;
                    continue;
                }
            }

            dependencies.add(d);
        }

        // MSHADE-155
        model.setArtifactId(shadedArtifactId);

        // MSHADE-185: We will add those system scoped dependencies
        // from the non interpolated original pom file. So we keep
        // things like this: <systemPath>${tools.jar}</systemPath> intact.
        addSystemScopedDependencyFromNonInterpolatedPom(dependencies, originalDependencies);

        // Check to see if we have a reduction and if so rewrite the POM.
        rewriteDependencyReducedPomIfWeHaveReduction(dependencies, modified, transitiveDeps, model);
    }