void (@NotNull Collection<? extends Library> libraries, VirtualFile[] roots) { WriteAction.run(() -> { for (Library library : libraries) { Library.ModifiableModel model = library.getModifiableModel(); Set<VirtualFile> alreadyExistingFiles = ContainerUtil.newHashSet(model.getFiles(OrderRootType.SOURCES)); for (VirtualFile root : roots) { if (!alreadyExistingFiles.contains(root)) { model.addRoot(root, OrderRootType.SOURCES); } } model.commit(); } }); }