public static void saveToJar(@NotNull Collection<RawRuntimeModuleDescriptor> descriptors,
                               @Nullable String bootstrapModuleName,
                               @NotNull Path jarFile,
                               @Nullable String mainPluginModuleId,
                               int generatorVersion)
    throws IOException, XMLStreamException {
    Files.createDirectories(jarFile.getParent());
    Manifest manifest = new Manifest();
    Attributes attributes = manifest.getMainAttributes();
    attributes.put(Attributes.Name.MANIFEST_VERSION, "1.0");
    attributes.put(Attributes.Name.SPECIFICATION_TITLE, SPECIFICATION_TITLE);
    attributes.put(Attributes.Name.SPECIFICATION_VERSION, SPECIFICATION_VERSION);
    attributes.put(Attributes.Name.IMPLEMENTATION_VERSION, SPECIFICATION_VERSION + "." + generatorVersion);
    if (bootstrapModuleName != null) {
      attributes.put(BOOTSTRAP_MODULE_ATTRIBUTE_NAME, bootstrapModuleName);
      attributes.put(BOOTSTRAP_CLASSPATH_ATTRIBUTE_NAME, computeClasspath(descriptors, bootstrapModuleName));
    }
    if (mainPluginModuleId != null) {
      attributes.put(MAIN_PLUGIN_MODULE_ATTRIBUTE_NAME, mainPluginModuleId);
    }
    try (JarOutputStream jarOutput = new JarOutputStream(new BufferedOutputStream(Files.newOutputStream(jarFile)), manifest)) {
      XMLOutputFactory factory = XMLOutputFactory.newDefaultFactory();
      for (RawRuntimeModuleDescriptor descriptor : descriptors) {
        String id = descriptor.getId();
        jarOutput.putNextEntry(new JarEntry(id + ".xml"));
        PrintWriter output = new PrintWriter(jarOutput, false, StandardCharsets.UTF_8);
        ModuleXmlSerializer.writeModuleXml(descriptor, output, factory);
        jarOutput.closeEntry();
      }
    }
  }
public static void saveToJar(@NotNull Collection<RawRuntimeModuleDescriptor> descriptors,
                               @Nullable String bootstrapModuleName,
                               @NotNull Path jarFile,
                               @Nullable String mainPluginModuleId,
                               int generatorVersion)