void (@NotNull Module module, @NotNull final ModifiableRootModel rootModel, @NotNull ModifiableModelsProvider modifiableModelsProvider, @Nullable DependencyScope scope) { LibraryTable.ModifiableModel modifiableModel = modifiableModelsProvider.getLibraryTableModifiableModel(module.getProject()); Library library = Iterables.find(Arrays.asList(modifiableModel.getLibraries()), library1 -> isLibraryEqualsToSelected(library1), null); if (library == null) { library = createNewLibrary(module, modifiableModel); } else { modifiableModelsProvider.disposeLibraryTableModifiableModel(modifiableModel); } final DependencyScope dependencyScope = scope != null ? scope : LibraryDependencyScopeSuggester.getDefaultScope(library); final ModifiableRootModel moduleModifiableModel = modifiableModelsProvider.getModuleModifiableModel(module); LibraryOrderEntry foundEntry = (LibraryOrderEntry)Iterables.find(Arrays.asList(moduleModifiableModel.getOrderEntries()), entry -> entry instanceof LibraryOrderEntry && ((LibraryOrderEntry)entry).getScope() == dependencyScope && isLibraryEqualsToSelected(((LibraryOrderEntry)entry).getLibrary()), null); modifiableModelsProvider.disposeModuleModifiableModel(moduleModifiableModel); if (foundEntry == null) { rootModel.addLibraryEntry(library).setScope(dependencyScope); } }