private void resolveIfNecessary(
     MavenArtifactInfo info,
     List<MavenRemoteRepository> repos,
     Map<MavenArtifactInfo, MavenArtifact> resolvedArtifacts)
     throws RemoteException {
   if (resolvedArtifacts.containsKey(info)) return;
   resolvedArtifacts.put(info, doResolve(info, repos));
 }
  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;
  }
  private void printIntellijIDEASettings(
      DecentGrailsLauncher launcher, Field settingsField, Set<Artifact> pluginArtifacts) {
    try {
      Object settings = settingsField.get(launcher);
      Field configField = settings.getClass().getSuperclass().getDeclaredField("config");
      configField.setAccessible(true);
      Object config = configField.get(settings);
      Map flatten = (Map) config.getClass().getDeclaredMethod("flatten").invoke(config);

      System.out.println();
      System.out.println(SETTINGS_START_MARKER);

      for (Object key : flatten.keySet()) {
        Object value = flatten.get(key);
        if (value instanceof String || value instanceof GString) {
          String realKey = key.toString();
          if (GRAILS_PROPERTY_LIST.contains(realKey)) {
            System.out.println(realKey + "=" + value.toString().replace('\\', '/'));
          }
        }
      }

      for (Artifact plugin : pluginArtifacts) {
        File targetDir = getPluginTargetDir(plugin);
        System.out.println(
            "grails.plugin.location."
                + getPluginName(plugin)
                + "="
                + targetDir.getAbsolutePath().replace('\\', '/'));
      }

      System.out.println();
      System.out.println(SETTINGS_END_MARKER);
    } catch (Exception ex) {
      getLog().error("Unable to get flattened configuration data", ex);
    }
  }
  @Override
  public Collection<MavenArtifact> resolvePlugin(
      @NotNull MavenPlugin plugin,
      @NotNull List<MavenRemoteRepository> repositories,
      int nativeMavenProjectId,
      boolean transitive)
      throws RemoteException, MavenServerProcessCanceledException {
    try {
      Plugin mavenPlugin = new Plugin();
      mavenPlugin.setGroupId(plugin.getGroupId());
      mavenPlugin.setArtifactId(plugin.getArtifactId());
      mavenPlugin.setVersion(plugin.getVersion());
      MavenProject project = RemoteNativeMavenProjectHolder.findProjectById(nativeMavenProjectId);

      MavenExecutionRequest request =
          createRequest(
              null,
              Collections.<String>emptyList(),
              Collections.<String>emptyList(),
              Collections.<String>emptyList());

      DefaultMaven maven = (DefaultMaven) getComponent(Maven.class);
      RepositorySystemSession repositorySystemSession = maven.newRepositorySession(request);

      if (plugin.getVersion() == null) {
        PluginVersionRequest versionRequest =
            new DefaultPluginVersionRequest(
                mavenPlugin, repositorySystemSession, project.getRemotePluginRepositories());
        mavenPlugin.setVersion(
            getComponent(PluginVersionResolver.class).resolve(versionRequest).getVersion());
      }

      PluginDescriptor result =
          getComponent(MavenPluginManager.class)
              .getPluginDescriptor(
                  mavenPlugin, project.getRemotePluginRepositories(), repositorySystemSession);

      Map<MavenArtifactInfo, MavenArtifact> resolvedArtifacts =
          new THashMap<MavenArtifactInfo, MavenArtifact>();

      Artifact pluginArtifact = result.getPluginArtifact();

      MavenArtifactInfo artifactInfo =
          new MavenArtifactInfo(
              pluginArtifact.getGroupId(),
              pluginArtifact.getArtifactId(),
              pluginArtifact.getVersion(),
              pluginArtifact.getType(),
              null);

      resolveIfNecessary(artifactInfo, repositories, resolvedArtifacts);

      if (transitive) {
        // todo try to use parallel downloading
        for (Artifact each : result.getIntroducedDependencyArtifacts()) {
          resolveIfNecessary(
              new MavenArtifactInfo(
                  each.getGroupId(), each.getArtifactId(), each.getVersion(), each.getType(), null),
              repositories,
              resolvedArtifacts);
        }
        for (ComponentDependency each : result.getDependencies()) {
          resolveIfNecessary(
              new MavenArtifactInfo(
                  each.getGroupId(), each.getArtifactId(), each.getVersion(), each.getType(), null),
              repositories,
              resolvedArtifacts);
        }
      }

      return new THashSet<MavenArtifact>(resolvedArtifacts.values());
    } catch (Exception e) {
      Maven3ServerGlobals.getLogger().info(e);
      return Collections.emptyList();
    }
  }