@NotNull
  private GradleProject doResolveProjectInfo(
      @NotNull final GradleTaskId id,
      @NotNull String projectPath,
      @NotNull ProjectConnection connection,
      boolean downloadLibraries)
      throws IllegalArgumentException, IllegalStateException {
    ModelBuilder<? extends IdeaProject> modelBuilder =
        myHelper.getModelBuilder(id, connection, downloadLibraries);
    IdeaProject project = modelBuilder.get();
    GradleProject result = populateProject(project, projectPath);

    // We need two different steps ('create' and 'populate') in order to handle module dependencies,
    // i.e. when one module is
    // configured to be dependency for another one, corresponding dependency module object should be
    // available during
    // populating dependent module object.
    Map<String, Pair<GradleModule, IdeaModule>> modules = createModules(project, result);
    populateModules(modules.values(), result);
    myLibraryNamesMixer.mixNames(result.getLibraries());
    return result;
  }
  @NotNull
  private static AbstractGradleDependency buildDependency(
      @NotNull GradleModule ownerModule,
      @NotNull IdeaSingleEntryLibraryDependency dependency,
      @NotNull GradleProject intellijProject)
      throws IllegalStateException {
    File binaryPath = dependency.getFile();
    if (binaryPath == null) {
      throw new IllegalStateException(
          String.format(
              "Can't parse external library dependency '%s'. Reason: it doesn't specify path to the binaries",
              dependency));
    }

    // Gradle API doesn't provide library name at the moment.
    GradleLibrary library = new GradleLibrary(FileUtil.getNameWithoutExtension(binaryPath));
    library.addPath(LibraryPathType.BINARY, binaryPath.getAbsolutePath());

    File sourcePath = dependency.getSource();
    if (sourcePath != null) {
      library.addPath(LibraryPathType.SOURCE, sourcePath.getAbsolutePath());
    }

    File javadocPath = dependency.getJavadoc();
    if (javadocPath != null) {
      library.addPath(LibraryPathType.DOC, javadocPath.getAbsolutePath());
    }

    if (!intellijProject.addLibrary(library)) {
      for (GradleLibrary registeredLibrary : intellijProject.getLibraries()) {
        if (registeredLibrary.equals(library)) {
          return new GradleLibraryDependency(ownerModule, registeredLibrary);
        }
      }
    }

    return new GradleLibraryDependency(ownerModule, library);
  }