void (@NotNull Module module, @NotNull ModifiableRootModel model) { final LibraryTable.ModifiableModel tableModel = model.getModuleLibraryTable().getModifiableModel(); Library library = tableModel.createLibrary(myCoordinates[0]); final Library.ModifiableModel libraryModel = library.getModifiableModel(); for (String coordinates : myCoordinates) { Collection<OrderRoot> roots = loadRoots(module.getProject(), coordinates); for (OrderRoot root : roots) { libraryModel.addRoot(root.getFile(), root.getType()); } } WriteAction.runAndWait(() -> { libraryModel.commit(); tableModel.commit(); }); model.findLibraryOrderEntry(library).setScope(myDependencyScope); }