Library (LibraryEx library) { final VirtualFile baseDir = getBaseDir(); final String libPath = baseDir != null ? baseDir.getPath() + "/lib" : ""; final VirtualFile[] classesRoots = library.getFiles(OrderRootType.CLASSES); boolean allowEmptyName = isConvertingToModuleLibrary() && classesRoots.length == 1; final String libraryName = allowEmptyName ? "" : StringUtil.notNullize(library.getName(), LibraryTypeServiceImpl.suggestLibraryName(classesRoots)); final LibraryTableModifiableModelProvider provider = getModifiableTableModelProvider(); final ChangeLibraryLevelDialog dialog = new ChangeLibraryLevelDialog(getParentComponent(), myProject, myCopy, libraryName, libPath, allowEmptyName, provider); if (!dialog.showAndGet()) { return null; } final Set<File> fileToCopy = new LinkedHashSet<>(); final Map<String, String> copiedFiles = new HashMap<>(); final String targetDirectoryPath = dialog.getDirectoryForFilesPath(); if (targetDirectoryPath != null) { for (OrderRootType type : OrderRootType.getAllTypes()) { for (VirtualFile root : library.getFiles(type)) { if (root.isInLocalFileSystem() || root.getFileSystem() instanceof ArchiveFileSystem) { fileToCopy.add(VfsUtilCore.virtualToIoFile(VfsUtil.getLocalFile(root))); } } } if (!copyOrMoveFiles(fileToCopy, targetDirectoryPath, copiedFiles)) { return null; } } final Library copied = provider.getModifiableModel().createLibrary(StringUtil.nullize(dialog.getLibraryName()), library.getKind()); final LibraryEx.ModifiableModelEx model = (LibraryEx.ModifiableModelEx)copied.getModifiableModel(); LibraryEditingUtil.copyLibrary(library, copiedFiles, model); /* Verification and bind JAR repositories are prohibited for global libraries */ if (isConvertingToApplicationLibrary() && model.getProperties() instanceof RepositoryLibraryProperties repositoryLibraryProperties) { model.setProperties(repositoryLibraryProperties.cloneAndChange(properties -> { properties.disableVerification(); properties.unbindRemoteRepository(); })); } WriteAction.run(() -> model.commit()); return copied; }