Library (@NotNull ModifiableRootModel model, String libName, @NotNull String libPath, String @NotNull ... jarArr) { List<VirtualFile> classesRoots = new ArrayList<>(); for (String jar : jarArr) { if (!libPath.endsWith("/") && !jar.startsWith("/")) { jar = "/" + jar; } String path = libPath + jar; VirtualFile root; if (path.endsWith(".jar")) { root = JarFileSystem.getInstance().refreshAndFindFileByPath(path + "!/"); } else { root = LocalFileSystem.getInstance().refreshAndFindFileByPath(path); } assert root != null : "Library root folder not found: " + path + "!/"; classesRoots.add(root); } LibraryTable libraryTable = LibraryTablesRegistrar.getInstance().getLibraryTable(model.getProject()); if (libraryTable.getLibraryByName(libName) != null) { for (int index = 0; index < 100000; index++) { String candidate = libName + "-" + index; if (libraryTable.getLibraryByName(candidate) == null) { libName = candidate; break; } } } return addProjectLibrary(model, libName, classesRoots, Collections.emptyList(), Collections.emptyList(), Collections.emptyList()); }