fix bug in srcjar generation
diff --git a/kotlin/builder/src/io/bazel/kotlin/builder/tasks/jvm/KotlinJvmTaskExecutor.kt b/kotlin/builder/src/io/bazel/kotlin/builder/tasks/jvm/KotlinJvmTaskExecutor.kt
index 978d465..75dcab5 100644
--- a/kotlin/builder/src/io/bazel/kotlin/builder/tasks/jvm/KotlinJvmTaskExecutor.kt
+++ b/kotlin/builder/src/io/bazel/kotlin/builder/tasks/jvm/KotlinJvmTaskExecutor.kt
@@ -59,13 +59,18 @@
             SourceJarCreator(
                 sourceJarPath
             ).also { creator ->
+                // This check asserts that source jars were unpacked.
+                check(
+                    command.inputs.sourceJarsList.isEmpty() ||
+                            Files.exists(Paths.get(command.directories.temp).resolve("_srcjars"))
+                )
                 listOf(
+                    // Any (input) source jars should already have been expanded so do not add them here.
                     command.inputs.javaSourcesList.stream(),
-                    command.inputs.kotlinSourcesList.stream(),
-                    command.inputs.sourceJarsList.stream()
-                ).stream().flatMap { it.map { Paths.get(it) } }.also {
-                    creator.addSources(it)
-                }
+                    command.inputs.kotlinSourcesList.stream()
+                ).stream()
+                    .flatMap { it.map { Paths.get(it) } }
+                    .also { creator.addSources(it) }
                 creator.execute()
             }
         }
diff --git a/kotlin/builder/src/io/bazel/kotlin/builder/utils/jars/SourceJarCreator.kt b/kotlin/builder/src/io/bazel/kotlin/builder/utils/jars/SourceJarCreator.kt
index a0a7c95..b30431b 100644
--- a/kotlin/builder/src/io/bazel/kotlin/builder/utils/jars/SourceJarCreator.kt
+++ b/kotlin/builder/src/io/bazel/kotlin/builder/utils/jars/SourceJarCreator.kt
@@ -129,13 +129,13 @@
      * Add a single source jar
      */
     private fun addSourceJar(path: Path) {
-        if(verbose) {
+        if (verbose) {
             System.err.println("adding source jar: $path")
         }
         JarFile(path.toFile()).use { jar ->
             for (entry in jar.entries()) {
                 if (!entry.isDirectory) {
-                    if (entry.name.endsWith(".kt") or entry.name.endsWith(".java")) {
+                    if (isJavaSourceLike(entry.name)) {
                         jar.getInputStream(entry).readBytes(entry.size.toInt()).also {
                             addEntry(entry.name, path, it)
                         }
@@ -162,7 +162,13 @@
         }
         filenameHelper.visitDeferredEntries { path, jarFilename, bytes ->
             if (jarFilename == null) {
-                System.err.println("could not determine jar entry name for $path. Body:\n${bytes.toString(Charset.defaultCharset())}}")
+                if (verbose) {
+                    val body = bytes.toString(Charset.defaultCharset())
+                    System.err.println("""could not determine jar entry name for $path. Body:\n$body}""")
+                } else {
+                    // if not verbose silently add files at the root.
+                    addEntry(path.fileName.toString(), path, bytes)
+                }
             } else {
                 System.err.println("adding deferred source file $path -> $jarFilename")
                 addEntry(jarFilename, path, bytes)