void (@NotNull Module module, @Nullable String libName, @NotNull List<String> classesRootUrls, @NotNull List<String> sourceRootUrls, @NotNull List<String> excludedRootUrls, @NotNull DependencyScope scope, boolean exported, Consumer<? super LibraryEx.ModifiableModelEx> postProcessor) { updateModel(module, model -> { LibraryEx library = (LibraryEx)model.getModuleLibraryTable().createLibrary(libName); LibraryEx.ModifiableModelEx libraryModel = library.getModifiableModel(); for (String rootUrl : classesRootUrls) { libraryModel.addRoot(rootUrl, OrderRootType.CLASSES); } for (String rootUrl : sourceRootUrls) { libraryModel.addRoot(rootUrl, OrderRootType.SOURCES); } for (String excludedUrl : excludedRootUrls) { libraryModel.addExcludedRoot(excludedUrl); } LibraryOrderEntry entry = model.findLibraryOrderEntry(library); assert entry != null : library; entry.setScope(scope); entry.setExported(exported); postProcessor.consume(libraryModel); ApplicationManager.getApplication().invokeAndWait(() -> WriteAction.run(libraryModel::commit)); }); }