@Nullable
  private static LibraryOrderEntry findLibraryOrderEntry(@NotNull ModifiableRootModel moduleRootModel,
                                                         @NotNull Library library,
                                                         @NotNull DependencyScope scope) {
    LibraryOrderEntry candidate = null;
    for (OrderEntry orderEntry : moduleRootModel.getOrderEntries()) {
      if (orderEntry instanceof LibraryOrderEntry libraryOrderEntry) {
        Library orderEntryLibrary = libraryOrderEntry.getLibrary();
        if (library == orderEntryLibrary) {
          return libraryOrderEntry;
        }
        // LibraryImpl.equals will return true for unrelated module library if it's just created and empty
        if (library.equals(orderEntryLibrary) && (candidate == null || libraryOrderEntry.getScope() == scope)) {
          candidate = libraryOrderEntry;
        }
      }
    }
    return candidate;
  }
@Nullable
  private static LibraryOrderEntry findLibraryOrderEntry(@NotNull ModifiableRootModel moduleRootModel,
                                                         @NotNull Library library,
                                                         @NotNull DependencyScope scope)