public static Set resolveArtifacts()

in plugins/gradle/gradle-plugin/src/main/java/org/wildfly/swarm/plugin/gradle/GradleDependencyResolutionHelper.java [109:165]


    public static Set<ArtifactSpec> resolveArtifacts(Project project, Collection<ArtifactSpec> specs, boolean transitive,
                                                     boolean excludeDefaults) {
        if (project == null) {
            throw new IllegalArgumentException("Gradle project reference cannot be null.");
        }
        if (specs == null) {
            project.getLogger().warn("Artifact specification collection is null.");
            return Collections.emptySet();
        }

        // Early return if there is nothing to resolve.
        if (specs.isEmpty()) {
            return Collections.emptySet();
        }

        final Configuration config = project.getConfigurations().detachedConfiguration().setTransitive(transitive);
        final DependencySet dependencySet = config.getDependencies();
        final Map<String, Project> projectGAVCoordinates = getAllProjects(project);
        final ProjectAccessListener listener = new DefaultProjectAccessListener();

        Set<ArtifactSpec> result = new HashSet<>();
        specs.forEach(s -> {
            // 1. Do we need to resolve this entry?
            final String specGAV = String.format(GROUP_ARTIFACT_VERSION_FORMAT, s.groupId(), s.artifactId(), s.version());
            boolean resolved = s.file != null;
            boolean projectEntry = projectGAVCoordinates.containsKey(specGAV);

            // 2. Should we skip this spec?
            if (excludeDefaults && FractionDescriptor.THORNTAIL_GROUP_ID.equals(s.groupId()) && !projectEntry) {
                return;
            }

            // 3. Should this entry be resolved?
            if (!resolved || transitive) {
                // a.) Does this entry represent a project dependency?
                if (projectGAVCoordinates.containsKey(specGAV)) {
                    dependencySet.add(new DefaultProjectDependency((ProjectInternal) projectGAVCoordinates.get(specGAV), listener, false));
                } else {
                    DefaultExternalModuleDependency d = new DefaultExternalModuleDependency(s.groupId(), s.artifactId(), s.version());
                    DefaultDependencyArtifact da = new DefaultDependencyArtifact(s.artifactId(), s.type(), s.type(), s.classifier(), null);
                    d.addArtifact(da);
                    dependencySet.add(d);
                }
            } else {
                // 4. Nothing else to do, just add the spec to the result.
                result.add(s);
            }
        });

        // 5. Are there any specs that need resolution?
        if (!dependencySet.isEmpty()) {
            config.getResolvedConfiguration().getResolvedArtifacts().stream()
                    .map(ra -> asDescriptor("compile", ra).toArtifactSpec())
                    .forEach(result::add);
        }
        return result;
    }