Library (final String name, final @Nullable VirtualFile classesRoot, final @Nullable VirtualFile sourceRoot) { return WriteAction.compute(() -> { final Library library = LibraryTablesRegistrar.getInstance().getLibraryTable(myProject).createLibrary(name); final Library.ModifiableModel model = library.getModifiableModel(); if (classesRoot != null) { model.addRoot(classesRoot, OrderRootType.CLASSES); } if (sourceRoot != null) { model.addRoot(sourceRoot, OrderRootType.SOURCES); } model.commit(); return library; }); }