void (@NotNull Module module, @NotNull Library library) { ModuleRootModificationUtil.updateModel(module, model -> { LibraryOrderEntry entry = model.findLibraryOrderEntry(library); if (entry != null) { model.removeOrderEntry(entry); } }); WriteCommandAction.runWriteCommandAction(null, ()-> { LibraryTable table = LibraryTablesRegistrar.getInstance().getLibraryTable(module.getProject()); LibraryTable.ModifiableModel model = table.getModifiableModel(); model.removeLibrary(library); model.commit(); }); }