directory refactor and class and source allignment with -2.params file ruleKind added
diff --git a/kotlin/builder/src/io/bazel/kotlin/builder/Args.kt b/kotlin/builder/src/io/bazel/kotlin/builder/Args.kt
index 84f4973..eb6bfb0 100644
--- a/kotlin/builder/src/io/bazel/kotlin/builder/Args.kt
+++ b/kotlin/builder/src/io/bazel/kotlin/builder/Args.kt
@@ -18,6 +18,8 @@
 
 import com.squareup.moshi.KotlinJsonAdapterFactory
 import com.squareup.moshi.Moshi
+import java.nio.file.Files
+import java.nio.file.Paths
 
 typealias ArgMap = Map<String, List<String>>
 
@@ -27,6 +29,13 @@
 fun ArgMap.mandatorySingle(key: String): String =
         optionalSingle(key) ?: throw IllegalArgumentException("$key is not optional")
 
+/**
+ * A flag bound to a directory that is lazily created.
+ */
+fun ArgMap.lazilyCreatedDirectory(key: String) = lazy {
+    mandatorySingle(key).let { Files.createDirectories(Paths.get(it)) }
+}
+
 fun ArgMap.optionalSingle(key: String): String? =
         optional(key)?.let {
             when (it.size) {
diff --git a/kotlin/builder/src/io/bazel/kotlin/builder/mode/jvm/actions/CreateOutputJar.kt b/kotlin/builder/src/io/bazel/kotlin/builder/mode/jvm/actions/CreateOutputJar.kt
index b65f9e6..ca94178 100644
--- a/kotlin/builder/src/io/bazel/kotlin/builder/mode/jvm/actions/CreateOutputJar.kt
+++ b/kotlin/builder/src/io/bazel/kotlin/builder/mode/jvm/actions/CreateOutputJar.kt
@@ -18,7 +18,6 @@
 import io.bazel.kotlin.builder.BuildAction
 import io.bazel.kotlin.builder.Context
 import io.bazel.kotlin.builder.KotlinToolchain
-import io.bazel.kotlin.builder.model.CompileDirectories
 import io.bazel.kotlin.builder.utils.executeAndAwaitSuccess
 import java.nio.file.Path
 
@@ -28,22 +27,13 @@
 class CreateOutputJar(toolchain: KotlinToolchain) : BuildAction("create output jar", toolchain) {
     private fun MutableList<String>.addAllFrom(dir: Path) = addAll(arrayOf("-C", dir.toString(), "."))
 
-    private fun MutableList<String>.maybeAddAnnotationProcessingGeneratedClasses(ctx: Context) {
-        ctx.flags.plugins?.let { pluginDescriptor ->
-            CompileDirectories[ctx].annotionProcessingClasses.takeIf {
-                pluginDescriptor.processors.isNotEmpty() && it.toFile().exists()
-            }?.also { this.addAllFrom(it) }
-        }
-    }
-
     override fun invoke(ctx: Context): Int {
         try {
             mutableListOf(
                     toolchain.JAR_TOOL_PATH,
                     "cf", ctx.flags.outputClassJar
             ).also { args ->
-                args.addAllFrom(CompileDirectories[ctx].classes)
-                args.maybeAddAnnotationProcessingGeneratedClasses(ctx)
+                args.addAllFrom(ctx.flags.classDir.value)
             }.also { executeAndAwaitSuccess(10, *it.toTypedArray()) }
         } catch (e: Exception) {
             throw RuntimeException("unable to create class jar", e)
diff --git a/kotlin/builder/src/io/bazel/kotlin/builder/mode/jvm/actions/GenerateJdepsFile.kt b/kotlin/builder/src/io/bazel/kotlin/builder/mode/jvm/actions/GenerateJdepsFile.kt
index 07c851c..f4971f2 100644
--- a/kotlin/builder/src/io/bazel/kotlin/builder/mode/jvm/actions/GenerateJdepsFile.kt
+++ b/kotlin/builder/src/io/bazel/kotlin/builder/mode/jvm/actions/GenerateJdepsFile.kt
@@ -20,6 +20,7 @@
 import io.bazel.kotlin.builder.Context
 import io.bazel.kotlin.builder.KotlinToolchain
 import io.bazel.kotlin.builder.mode.jvm.utils.JdepsParser
+import io.bazel.kotlin.builder.model.Metas
 import io.bazel.kotlin.builder.utils.executeAndWaitOutput
 import io.bazel.kotlin.builder.utils.rootCause
 import java.io.FileOutputStream
@@ -32,13 +33,13 @@
 
     override fun invoke(ctx: Context): Int {
         val jdepsContent: Deps.Dependencies
-
+        val classpath = Metas.CLASSPATH_STRING[ctx]
         try {
-            jdepsContent = executeAndWaitOutput(10, toolchain.JDEPS_PATH, "-cp", ctx.flags.classpath, ctx.flags.outputClassJar).let {
+            jdepsContent = executeAndWaitOutput(10, toolchain.JDEPS_PATH, "-cp", classpath, ctx.flags.outputClassJar).let {
                 JdepsParser.parse(
                         ctx.flags.label,
                         ctx.flags.outputClassJar,
-                        ctx.flags.classpath,
+                        classpath,
                         it.stream(), isKotlinImplicit)
             }
         } catch (e: Exception) {
diff --git a/kotlin/builder/src/io/bazel/kotlin/builder/mode/jvm/actions/Initialize.kt b/kotlin/builder/src/io/bazel/kotlin/builder/mode/jvm/actions/Initialize.kt
index 526c333..845bf92 100644
--- a/kotlin/builder/src/io/bazel/kotlin/builder/mode/jvm/actions/Initialize.kt
+++ b/kotlin/builder/src/io/bazel/kotlin/builder/mode/jvm/actions/Initialize.kt
@@ -19,12 +19,9 @@
 import io.bazel.kotlin.builder.BuildAction
 import io.bazel.kotlin.builder.Context
 import io.bazel.kotlin.builder.KotlinToolchain
-import io.bazel.kotlin.builder.model.CompileDirectories
 import io.bazel.kotlin.builder.model.CompilePluginConfig
 import io.bazel.kotlin.builder.model.Metas
 import io.bazel.kotlin.builder.utils.PluginArgs
-import java.nio.file.Files
-import java.nio.file.Paths
 
 /**
  * Should be the first step, does mandatory pre-processing.
@@ -32,14 +29,18 @@
 class Initialize(toolchain: KotlinToolchain) : BuildAction("initialize KotlinBuilder", toolchain) {
     override fun invoke(ctx: Context): Int {
         ctx.apply(
-                ::initializeAndBindBindDirectories,
                 ::bindLabelComponents,
                 ::bindPluginStatus,
-                ::bindSources
+                ::bindSources,
+                ::memoize
         )
         return 0
     }
 
+    private fun memoize(ctx: Context) {
+        Metas.CLASSPATH_STRING[ctx] = ctx.flags.classpath.joinToString(":")
+    }
+
     private fun bindPluginStatus(ctx: Context) {
         CompilePluginConfig[ctx] = ctx.flags.plugins?.let {
             PluginArgs.from(ctx)?.let {
@@ -51,7 +52,7 @@
     private fun bindSources(ctx: Context) {
         val javaSources = mutableListOf<String>()
         val allSources = mutableListOf<String>()
-        for (src in requireNotNull(ctx.flags.source).split(":")) {
+        for (src in ctx.flags.source) {
             when {
                 src.endsWith(".java") -> {
                     javaSources.add(src)
@@ -65,12 +66,6 @@
         Metas.ALL_SOURCES[ctx] = allSources.toList()
     }
 
-    private fun initializeAndBindBindDirectories(ctx: Context) {
-        Files.createDirectories(Paths.get(ctx.flags.compilerOutputBase)).let {
-            CompileDirectories[ctx] = CompileDirectories(it)
-        }
-    }
-
     /**
      * parses the label, sets up the meta elements and returns the target part.
      */
diff --git a/kotlin/builder/src/io/bazel/kotlin/builder/mode/jvm/actions/JavaMainCompile.kt b/kotlin/builder/src/io/bazel/kotlin/builder/mode/jvm/actions/JavaMainCompile.kt
index 4393818..bed49a6 100644
--- a/kotlin/builder/src/io/bazel/kotlin/builder/mode/jvm/actions/JavaMainCompile.kt
+++ b/kotlin/builder/src/io/bazel/kotlin/builder/mode/jvm/actions/JavaMainCompile.kt
@@ -19,7 +19,6 @@
 import io.bazel.kotlin.builder.CompileResult
 import io.bazel.kotlin.builder.Context
 import io.bazel.kotlin.builder.KotlinToolchain
-import io.bazel.kotlin.builder.model.CompileDirectories
 import io.bazel.kotlin.builder.model.Metas
 import io.bazel.kotlin.builder.utils.annotationProcessingGeneratedJavaSources
 import io.bazel.kotlin.builder.utils.executeAndAwait
@@ -38,10 +37,10 @@
         val additionalJavaSources = ctx.annotationProcessingGeneratedJavaSources()?.toList() ?: emptyList()
 
         if (javaSources.isNotEmpty() || additionalJavaSources.isNotEmpty()) {
-            val classesDirectory = CompileDirectories[ctx].classes
-            val incrementalData = CompileDirectories[ctx].annotationProcessingIncrementalData
+            val classesDirectory = ctx.flags.classDir.value.toString()
+            val incrementalData = ctx.flags.tempDirPath.value.toString()
 
-            val args = mutableListOf(toolchain.JAVAC_PATH, "-cp", "$classesDirectory/:$incrementalData/:${ctx.flags.classpath}", "-d", classesDirectory.toString()).also {
+            val args = mutableListOf(toolchain.JAVAC_PATH, "-cp", "$classesDirectory/:$incrementalData/:${ctx.flags.classpath.joinToString(":")}", "-d", classesDirectory).also {
                 // Kotlin takes care of annotation processing.
                 it.add("-proc:none")
                 it.addAll(javaSources)
diff --git a/kotlin/builder/src/io/bazel/kotlin/builder/mode/jvm/actions/KotlinMainCompile.kt b/kotlin/builder/src/io/bazel/kotlin/builder/mode/jvm/actions/KotlinMainCompile.kt
index 5f0be66..0388516 100644
--- a/kotlin/builder/src/io/bazel/kotlin/builder/mode/jvm/actions/KotlinMainCompile.kt
+++ b/kotlin/builder/src/io/bazel/kotlin/builder/mode/jvm/actions/KotlinMainCompile.kt
@@ -21,7 +21,6 @@
 import io.bazel.kotlin.builder.Context
 import io.bazel.kotlin.builder.KotlinToolchain
 import io.bazel.kotlin.builder.mode.jvm.utils.KotlinCompilerOutputProcessor
-import io.bazel.kotlin.builder.model.CompileDirectories
 import io.bazel.kotlin.builder.model.CompilePluginConfig
 import io.bazel.kotlin.builder.model.Metas
 import io.bazel.kotlin.builder.utils.addAll
@@ -42,10 +41,9 @@
      */
     private fun setupCompileContext(ctx: Context): MutableList<String> {
         val args = mutableListOf<String>()
-        val compileDirectories = CompileDirectories[ctx]
 
         args.addAll(
-                "-cp", ctx.flags.classpath,
+                "-cp", Metas.CLASSPATH_STRING[ctx],
                 "-api-version", ctx.flags.kotlinApiVersion,
                 "-language-version", ctx.flags.kotlinLanguageVersion,
                 "-jvm-target", ctx.flags.kotlinJvmTarget
@@ -53,7 +51,7 @@
 
         args
                 .addAll("-module-name", ctx.moduleName)
-                .addAll("-d", compileDirectories.classes.toString())
+                .addAll("-d", ctx.flags.classDir.value.toString())
 
         ctx.flags.kotlinPassthroughFlags?.takeIf { it.isNotBlank() }?.also { args.addAll(it.split(" ")) }
 
diff --git a/kotlin/builder/src/io/bazel/kotlin/builder/model/CompileState.kt b/kotlin/builder/src/io/bazel/kotlin/builder/model/CompileState.kt
index 932fb32..0b29abe 100644
--- a/kotlin/builder/src/io/bazel/kotlin/builder/model/CompileState.kt
+++ b/kotlin/builder/src/io/bazel/kotlin/builder/model/CompileState.kt
@@ -16,40 +16,9 @@
 package io.bazel.kotlin.builder.model
 
 import io.bazel.kotlin.builder.MandatoryMeta
-import java.nio.file.Files
-import java.nio.file.Path
 
 sealed class CompileState
 
-/**
- * Temporary output directories used durng compilation.
- */
-class CompileDirectories(private val outputBase: Path) : CompileState() {
-    val classes by lazy { dir("_classes", create = true) }
-
-    /**
-     *  The generated sources that need to be compiled and included in the output jar.
-     */
-    val annotationProcessingSources by lazy { dir("_ap_sources") }
-    /**
-     * Files other than sources that should be directly bundled into the output jar, this could be resources.
-     */
-    val annotionProcessingClasses by lazy { dir("_ap_classes") }
-    val annotationProcessingStubs by lazy { dir("_ap_stubs") }
-    /**
-     * The classes generated in here are needed for javac to compile the generated sources.
-     */
-    val annotationProcessingIncrementalData by lazy { dir("_ap_incremental_data") }
-
-    private fun dir(component: String, create: Boolean = false): Path = outputBase.resolve(component).also {
-        if(create) {
-            Files.createDirectories(it)
-        }
-    }
-
-    companion object: MandatoryMeta<CompileDirectories>("compile_directories")
-}
-
 class CompilePluginConfig(
         val hasAnnotationProcessors: Boolean = false,
         val args: Array<String> = emptyArray()
diff --git a/kotlin/builder/src/io/bazel/kotlin/builder/model/Flags.kt b/kotlin/builder/src/io/bazel/kotlin/builder/model/Flags.kt
index a11283e..f41f875 100644
--- a/kotlin/builder/src/io/bazel/kotlin/builder/model/Flags.kt
+++ b/kotlin/builder/src/io/bazel/kotlin/builder/model/Flags.kt
@@ -22,13 +22,20 @@
  */
 class Flags(argMap: ArgMap) {
     val label = argMap.mandatorySingle(JavaBuilderFlags.TARGET_LABEL.flag)
+    val ruleKind = argMap.mandatorySingle(JavaBuilderFlags.RULE_KIND.flag)
+
+    val classDir = argMap.lazilyCreatedDirectory(JavaBuilderFlags.CLASSDIR.flag)
+    val tempDirPath = argMap.lazilyCreatedDirectory(JavaBuilderFlags.TEMPDIR.flag)
+    val sourceGenDir = argMap.lazilyCreatedDirectory(JavaBuilderFlags.SOURCEGEN_DIR.flag)
+
+    // val strictJavaDeps = argMap.mandatorySingle(JavaBuilderFlags.STRICT_JAVA_DEPS.flag)
     val outputClassJar = argMap.mandatorySingle(JavaBuilderFlags.OUTPUT.flag)
-    val source = argMap.mandatorySingle(JavaBuilderFlags.SOURCES.flag)
-    val classpath = argMap.mandatorySingle(JavaBuilderFlags.CLASSPATH.flag)
+
+    val source = argMap.mandatory(JavaBuilderFlags.SOURCES.flag)
+    val classpath = argMap.mandatory(JavaBuilderFlags.CLASSPATH.flag)
     val plugins = argMap.optionalFromJson<PluginDescriptors>("--kt-plugins")
     val outputJdeps = argMap.mandatorySingle("--output_jdeps")
 
-    val compilerOutputBase = argMap.mandatorySingle("--compiler_output_base")
     val kotlinApiVersion = argMap.mandatorySingle("--kotlin_api_version")
     val kotlinLanguageVersion = argMap.mandatorySingle("--kotlin_language_version")
     val kotlinJvmTarget = argMap.mandatorySingle("--kotlin_jvm_target")
diff --git a/kotlin/builder/src/io/bazel/kotlin/builder/model/Metas.kt b/kotlin/builder/src/io/bazel/kotlin/builder/model/Metas.kt
index e5c5f4c..48ec630 100644
--- a/kotlin/builder/src/io/bazel/kotlin/builder/model/Metas.kt
+++ b/kotlin/builder/src/io/bazel/kotlin/builder/model/Metas.kt
@@ -21,14 +21,17 @@
  * Listin of Meta keys that don't make sense as companion objects.
  */
 object Metas {
-    // mandatory: the package part of the label.
+    // the package part of the label.
     val PKG = MandatoryMeta<String>("package")
-    // mandatory: The target part of the label.
+    // The target part of the label.
     val TARGET = MandatoryMeta<String>("target")
 
-    // mandatory:  If this is non empty then it is a mixed mode operation.
+    //If this is non empty then it is a mixed mode operation.
     val JAVA_SOURCES = MandatoryMeta<List<String>>("java_sources")
 
-    // mandatory:
+
     val ALL_SOURCES = MandatoryMeta<List<String>>("all_sources")
+
+    // memoized classpath string
+    val CLASSPATH_STRING = MandatoryMeta<String>("joined_classpath")
 }
\ No newline at end of file
diff --git a/kotlin/builder/src/io/bazel/kotlin/builder/utils/PluginUtils.kt b/kotlin/builder/src/io/bazel/kotlin/builder/utils/PluginUtils.kt
index dfe1689..21c119c 100644
--- a/kotlin/builder/src/io/bazel/kotlin/builder/utils/PluginUtils.kt
+++ b/kotlin/builder/src/io/bazel/kotlin/builder/utils/PluginUtils.kt
@@ -17,8 +17,6 @@
 
 import io.bazel.kotlin.builder.Context
 import io.bazel.kotlin.builder.KotlinToolchain.CompilerPlugin
-import io.bazel.kotlin.builder.model.CompileDirectories
-import io.bazel.kotlin.builder.model.CompilePluginConfig
 import java.io.ByteArrayOutputStream
 import java.io.ObjectOutputStream
 import java.util.*
@@ -64,13 +62,11 @@
         fun from(ctx: Context): List<String>? =
                 ctx.flags.plugins?.let { descriptor ->
                     if (descriptor.processors.isNotEmpty()) {
-                        val compileDirectories = CompileDirectories[ctx]
-
                         PluginArgs(ctx.toolchain.KAPT_PLUGIN).let { arg ->
-                            arg["sources"] = compileDirectories.annotationProcessingSources.toString()
-                            arg["classes"] = compileDirectories.annotionProcessingClasses.toString()
-                            arg["stubs"] = compileDirectories.annotationProcessingStubs.toString()
-                            arg["incrementalData"] = compileDirectories.annotationProcessingIncrementalData.toString()
+                            arg["sources"] = ctx.flags.sourceGenDir.value.toString()
+                            arg["classes"] = ctx.flags.classDir.value.toString()
+                            arg["stubs"] = ctx.flags.tempDirPath.value.toString()
+                            arg["incrementalData"] = ctx.flags.tempDirPath.value.toString()
 
                             arg["aptMode"] = "stubsAndApt"
                             arg["correctErrorTypes"] = "true"
@@ -88,10 +84,9 @@
     }
 }
 
-fun Context.annotationProcessingGeneratedSources(): Sequence<String>? {
-    return CompilePluginConfig[this].takeIf { it.hasAnnotationProcessors }?.let {
-        CompileDirectories[this].annotationProcessingSources.toFile().walkTopDown().filter { it.isFile }.map { it.path }
-    }
-}
+fun Context.annotationProcessingGeneratedSources(): Sequence<String>? =
+        if (flags.sourceGenDir.isInitialized()) {
+            flags.sourceGenDir.value.toFile().walkTopDown().filter { it.isFile }.map { it.path }
+        } else null
 
 fun Context.annotationProcessingGeneratedJavaSources(): Sequence<String>? = annotationProcessingGeneratedSources()?.filter { it.endsWith(".java") }
\ No newline at end of file
diff --git a/kotlin/internal/compile.bzl b/kotlin/internal/compile.bzl
index b2b6e91..eefee9e 100644
--- a/kotlin/internal/compile.bzl
+++ b/kotlin/internal/compile.bzl
@@ -15,31 +15,36 @@
 load("//kotlin/internal:plugins.bzl", "plugins")
 load("//kotlin/internal:utils.bzl", "utils")
 
-def _kotlin_do_compile_action(ctx, output_jar, compile_jars, opts):
+def _kotlin_do_compile_action(ctx, rule_kind, output_jar, compile_jars):
     """Internal macro that sets up a Kotlin compile action.
 
     This macro only supports a single Kotlin compile operation for a rule.
 
     Args:
-      ctx: the ctx of the rule in scope when this macro is called. The macro will pick up the following entities from
-        the rule ctx:
-          * The `srcs` to compile.
-      output_jar: The jar file that this macro will use as the output of the action -- a hardcoded default output is not
-        setup by this rule as this would close the door to optimizations for simple compile operations.
+      rule_kind: The rule kind,
+      output_jar: The jar file that this macro will use as the output of the action.
       compile_jars: The compile time jars provided on the classpath for the compile operations -- callers are
         responsible for preparing the classpath. The stdlib (and jdk7 + jdk8) should generally be added to the classpath
         by the caller -- kotlin-reflect could be optional.
-      opts: struct containing Kotlin compilation options.
     """
-    compiler_output_base=ctx.actions.declare_directory(ctx.label.name + "." + "kotlinc")
+    classes_directory=ctx.actions.declare_directory(ctx.label.name + "_classes")
+    sourcegen_directory=ctx.actions.declare_directory(ctx.label.name + "_sourcegendir")
+    temp_directory=ctx.actions.declare_directory(ctx.label.name + "_tempdir")
+
     tc=ctx.toolchains[kt.defs.TOOLCHAIN_TYPE]
+
     args = [
         "--target_label", ctx.label,
-        "--compiler_output_base", compiler_output_base.path,
+        "--rule_kind", rule_kind,
+
+        "--classdir", classes_directory.path,
+        "--sourcegendir", sourcegen_directory.path,
+        "--tempdir", temp_directory.path,
+
         "--output", output_jar.path,
         "--output_jdeps", ctx.outputs.jdeps.path,
-        "--classpath", ":".join([f.path for f in compile_jars.to_list()]),
-        "--sources", ":".join([f.path for f in ctx.files.srcs]),
+        "--classpath", "\n".join([f.path for f in compile_jars.to_list()]),
+        "--sources", "\n".join([f.path for f in ctx.files.srcs]),
         "--kotlin_jvm_target", tc.jvm_target,
         "--kotlin_api_version", tc.api_version,
         "--kotlin_language_version", tc.language_version,
@@ -52,7 +57,7 @@
         args += [ "--kt-plugins", plugin_info.to_json() ]
 
     # Declare and write out argument file.
-    args_file = ctx.actions.declare_file(ctx.label.name + "-worker.args")
+    args_file = ctx.actions.declare_file(ctx.label.name + ".jar-2.params")
     ctx.actions.write(args_file, "\n".join(args))
 
     # When a stratetegy isn't provided for the worker and the workspace is fresh then certain deps are not available under
@@ -68,24 +73,13 @@
     ctx.action(
         mnemonic = "KotlinCompile",
         inputs = compile_inputs,
-        outputs = [output_jar, ctx.outputs.jdeps, compiler_output_base],
+        outputs = [output_jar, ctx.outputs.jdeps, sourcegen_directory, classes_directory, temp_directory],
         executable = ctx.executable._kotlinw,
         execution_requirements = {"supports-workers": "1"},
         arguments = ["@" + args_file.path],
         progress_message="Compiling %d Kotlin source files to %s" % (len(ctx.files.srcs), output_jar.short_path),
     )
 
-def _select_compilation_options(ctx):
-  """TODO Stub: setup compilation options"""
-  return struct(
-      # Basic kotlin compile options.
-      opts = {},
-      # Advanced Kotlin compile options.
-      x_opts ={},
-      # Kotlin compiler plugin options.
-      plugin_opts = {}
-  )
-
 def _select_std_libs(ctx):
     return ctx.files._kotlin_std
 
@@ -156,7 +150,7 @@
         providers=[java_info,default_info,kotlin_info],
     )
 
-def _compile_action (ctx):
+def _compile_action (ctx, rule_kind):
     """Setup a kotlin compile action.
 
     Args:
@@ -188,10 +182,11 @@
     # setup the compile action.
     _kotlin_do_compile_action(
         ctx,
-        kt_compile_output_jar,
-        utils.collect_jars_for_compile(ctx.attr.deps) + kotlin_auto_deps,
-        _select_compilation_options(ctx)
+        rule_kind = rule_kind,
+        output_jar = kt_compile_output_jar,
+        compile_jars = utils.collect_jars_for_compile(ctx.attr.deps) + kotlin_auto_deps
     )
+
     # setup the merge action if needed.
     if len(output_merge_list) > 0:
         utils.actions.fold_jars(ctx, output_jar, output_merge_list)
diff --git a/kotlin/internal/rules.bzl b/kotlin/internal/rules.bzl
index 70ef7c8..00e9aeb 100644
--- a/kotlin/internal/rules.bzl
+++ b/kotlin/internal/rules.bzl
@@ -56,10 +56,10 @@
     return struct(kt = kotlin_info, providers= [default_info, java_info, kotlin_info])
 
 def kt_jvm_library_impl(ctx):
-    return compile.make_providers(ctx, compile.compile_action(ctx))
+    return compile.make_providers(ctx, compile.compile_action(ctx, "kt_jvm_library"))
 
 def kt_jvm_binary_impl(ctx):
-    java_info = compile.compile_action(ctx)
+    java_info = compile.compile_action(ctx, "kt_jvm_binary")
     utils.actions.write_launcher(
         ctx,
         java_info.transitive_runtime_jars,
@@ -77,7 +77,7 @@
     )
 
 def kt_jvm_junit_test_impl(ctx):
-    java_info = compile.compile_action(ctx)
+    java_info = compile.compile_action(ctx, "kt_jvm_test")
 
     transitive_runtime_jars = java_info.transitive_runtime_jars + ctx.files._bazel_test_runner
     launcherJvmFlags = ["-ea", "-Dbazel.test_suite=%s"% ctx.attr.test_class]