@Override
  public LibraryOrderEntry addLibraryDependency(MavenArtifact artifact,
                                                DependencyScope scope,
                                                IdeModifiableModelsProvider provider,
                                                MavenProject project) {
    assert !MavenConstants.SCOPE_SYSTEM.equals(
      artifact.getScope()); // System dependencies must be added ad module library, not as project wide library.

    myLibrariesTable = null;
    String libraryName = artifact.getLibraryName();

    Library library = provider.getLibraryByName(libraryName);
    if (library == null) {
      library = provider.createLibrary(libraryName, getMavenExternalSource());
    }
    Library.ModifiableModel libraryModel = provider.getModifiableLibraryModel(library);

    if (library.getExternalSource() == null) {
      ((LibraryEx.ModifiableModelEx)libraryModel).setExternalSource(getMavenExternalSource());
    }
    updateUrl(libraryModel, OrderRootType.CLASSES, artifact, null, null, true);
    updateUrl(libraryModel, OrderRootType.SOURCES, artifact, MavenExtraArtifactType.SOURCES, project, false);
    updateUrl(libraryModel, JavadocOrderRootType.getInstance(), artifact, MavenExtraArtifactType.DOCS, project, false);

    if (libraryModel != null) {
      LibraryEx.ModifiableModelEx model = (LibraryEx.ModifiableModelEx)libraryModel;
      PersistentLibraryKind<ImportedLibraryProperties> importedLibraryKind = ImportedLibraryType.Companion.getIMPORTED_LIBRARY_KIND();
      if (model.getKind() != importedLibraryKind) {
        model.setKind(importedLibraryKind);
        model.setProperties(new ImportedLibraryProperties(new MavenCoordinates(artifact.getGroupId(),
                                                                               artifact.getArtifactId(),
                                                                               artifact.getVersion(),
                                                                               artifact.getPackaging(),
                                                                               artifact.getClassifier())));
      }
    }


    LibraryOrderEntry e = myRootModel.addLibraryEntry(library);
    e.setScope(scope);

    if (myOrderEntriesBeforeJdk.contains(libraryName)) {
      moveLastOrderEntryBeforeJdk();
    }

    return e;
  }
@Override
  public LibraryOrderEntry addLibraryDependency(MavenArtifact artifact,
                                                DependencyScope scope,
                                                IdeModifiableModelsProvider provider,
                                                MavenProject project)