Set<Artifact> getResolvedArtifactsFromUnresolvedDependencies(
      List<Dependency> unresolvedDependencies, boolean resolveTransitively)
      throws MojoExecutionException {
    final Set<Artifact> resolvedArtifacts = new HashSet<Artifact>();
    //    Artifact mojoArtifact = this.artifactFactory.createBuildArtifact(project.getGroupId(),
    // project.getArtifactId(), project.getVersion(), "pom");

    /*
     * Resolve each artifact.  This will get all transitive artifacts AND eliminate conflicts.
     */
    final Set<Artifact> unresolvedArtifacts;

    //    for (Dependency d : unresolvedDependencies)
    //      System.out.println("dependency: " + d.toString());

    try {
      unresolvedArtifacts =
          MavenMetadataSource.createArtifacts(
              this.artifactFactory, unresolvedDependencies, null, null, null);
      //      for (Artifact artifact : unresolvedArtifacts) {
      //        System.out.println("unresolved " + artifact.toString());
      //      }

      if (resolveTransitively) {
        ArtifactResolutionResult artifacts =
            artifactResolver.resolveTransitively(
                unresolvedArtifacts,
                project.getArtifact(),
                remoteRepositories,
                localRepository,
                artifactMetadataSource);
        resolvedArtifacts.addAll(artifacts.getArtifacts());
      } else {
        // resolve each artifact individually
        for (Artifact artifact : unresolvedArtifacts) {
          artifactResolver.resolve(artifact, remoteRepositories, localRepository);

          resolvedArtifacts.add(artifact);
        }
      }

    } catch (Exception e) {
      throw new MojoExecutionException("Unable to complete configuring the build settings", e);
    }

    for (Artifact artifact : resolvedArtifacts) {
      System.out.println("matched " + artifact.toString());
    }

    return resolvedArtifacts;
  }
  private Set<Artifact> collectAllProjectArtifacts() throws MojoExecutionException {
    final Set<Artifact> resolvedArtifacts = new HashSet<Artifact>();

    /*
     * Get the Grails dependencies from the plugin's POM file first.
     */
    final MavenProject pluginProject;
    try {
      pluginProject = getPluginProject();
    } catch (ProjectBuildingException e) {
      throw new MojoExecutionException("Unable to get plugin project", e);
    }

    /*
     * Add the plugin's dependencies and the project using the plugin's dependencies to the list
     * of unresolved dependencies.  This is done so they can all be resolved at the same time so
     * that we get the benefit of Maven's conflict resolution.
     */

    Set<Artifact> uncheckedArtifacts =
        useTransitives
            ? resolveFromTree()
            : getResolvedArtifactsFromUnresolvedDependencies(project.getDependencies(), false);
    Map<String, Artifact> checklist = new HashMap<String, Artifact>();

    for (Artifact artifact : uncheckedArtifacts) {
      //      resolvedArtifacts.add(artifact);
      checklist.put(artifactToKey(artifact), artifact);
      //      resolvedArtifacts.add(artifact);
    }

    // major breaking change, no dependencies from plugin
    /*
        for( Artifact artifact : getResolvedArtifactsFromUnresolvedDependencies(replaceVersion(filterGrailsDependencies(pluginProject.getDependencies())), true) ) {

    //      resolvedArtifacts.add(artifact);

          String key = artifactToKey(artifact);
          Artifact existing = checklist.get(key);

          if (existing == null)
            checklist.put(key, artifact);
        }
        */

    resolvedArtifacts.addAll(checklist.values());

    return resolvedArtifacts;
  }