Repository: JetBrains/kotlin
File: compiler/cli/src/org/jetbrains/kotlin/cli/jvm/compiler/CompileEnvironmentUtil.java (Java)

Code before:
            Attributes mainAttributes = manifest.getMainAttributes();
            mainAttributes.putValue("Manifest-Version", "1.0");
            mainAttributes.putValue("Created-By", "JetBrains Kotlin");
            if (mainClass != null) {
                mainAttributes.putValue("Main-Class", mainClass.asString());
            }

            JarOutputStream stream = new JarOutputStream(fos);
            JarEntry manifestEntry = new JarEntry(JarFile.MANIFEST_NAME);
            if (resetJarTimestamps) {
                manifestEntry.setTime(DOS_EPOCH);
            }
            stream.putNextEntry(manifestEntry);
            manifest.write(new BufferedOutputStream(stream));

            for (OutputFile outputFile : outputFiles.asList()) {
                JarEntry entry = new JarEntry(outputFile.getRelativePath());
                if (resetJarTimestamps) {
                    entry.setTime(DOS_EPOCH);
                }
                stream.putNextEntry(entry);
                stream.write(outputFile.asByteArray());
            }
            if (includeRuntime) {
                writeRuntimeToJar(stream, resetJarTimestamps);
                writeReflectToJar(stream, resetJarTimestamps);
            }
            stream.finish();
        }
        catch (IOException e) {
            throw new CompileEnvironmentException("Failed to generate jar file", e);
        }
    }

    public static void writeToJar(
            File jarPath, boolean jarRuntime, boolean resetJarTimestamps, FqName mainClass, OutputFileCollection outputFiles
    ) {
        FileOutputStream outputStream = null;
        try {
            outputStream = new FileOutputStream(jarPath);
            doWriteToJar(outputFiles, outputStream, mainClass, jarRuntime, resetJarTimestamps);
            outputStream.close();
        }
        catch (FileNotFoundException e) {
            throw new CompileEnvironmentException("Invalid jar path " + jarPath, e);
        }
        catch (IOException e) {
            throw ExceptionUtilsKt.rethrow(e);
        }
        finally {
            ExceptionUtilsKt.closeQuietly(outputStream);

Review comment (suggestion):
As I mentioned in [KT-17344](https://youtrack.jetbrains.com/issue/KT-17344), I think we shouldn't pack kotlin-reflect if `-no-reflect` is specified. Having kotlin-reflect in the classpath can change the program behavior quite visibly, for example `toString` on lambdas will behave differently.

Could you take a look into it? If you do, please don't forget to add a test for the `-no-reflect` case. Otherwise I suppose it can be fixed separately

Code after:
            Attributes mainAttributes = manifest.getMainAttributes();
            mainAttributes.putValue("Manifest-Version", "1.0");
            mainAttributes.putValue("Created-By", "JetBrains Kotlin");
            if (mainClass != null) {
                mainAttributes.putValue("Main-Class", mainClass.asString());
            }

            JarOutputStream stream = new JarOutputStream(fos);
            JarEntry manifestEntry = new JarEntry(JarFile.MANIFEST_NAME);
            if (resetJarTimestamps) {
                manifestEntry.setTime(DOS_EPOCH);
            }
            stream.putNextEntry(manifestEntry);
            manifest.write(new BufferedOutputStream(stream));

            for (OutputFile outputFile : outputFiles.asList()) {
                JarEntry entry = new JarEntry(outputFile.getRelativePath());
                if (resetJarTimestamps) {
                    entry.setTime(DOS_EPOCH);
                }
                stream.putNextEntry(entry);
                stream.write(outputFile.asByteArray());
            }
            if (includeRuntime) {
                writeRuntimeToJar(stream, resetJarTimestamps);
            }
            stream.finish();
        }
        catch (IOException e) {
            throw new CompileEnvironmentException("Failed to generate jar file", e);
        }
    }

    public static void writeToJar(
            File jarPath, boolean jarRuntime, boolean resetJarTimestamps, FqName mainClass, OutputFileCollection outputFiles
    ) {
        FileOutputStream outputStream = null;
        try {
            outputStream = new FileOutputStream(jarPath);
            doWriteToJar(outputFiles, outputStream, mainClass, jarRuntime, resetJarTimestamps);
            outputStream.close();
        }
        catch (FileNotFoundException e) {
            throw new CompileEnvironmentException("Invalid jar path " + jarPath, e);
        }
        catch (IOException e) {
            throw ExceptionUtilsKt.rethrow(e);
        }
        finally {
            ExceptionUtilsKt.closeQuietly(outputStream);
        }