Bazel rules for Kotlin
Switch branches/tags
Clone or download
laurentlb Cleanup for Bazel incompatible changes (#169)
- Avoid depset concatenation and implicit iteration
- Avoid '+' operator on dictionaries
- Migrate to the Args methods
- Separate tools from other inputs

  bazel0.20 test :all --all_incompatible_changes --incompatible_disallow_legacy_javainfo=false
Latest commit cab5eaf Nov 28, 2018

Build status

Skydoc documentation


  • August 14, 2018. Js support. No documentation yet but see the nested example workspace examples/node.
  • August 14, 2018. Android support. No documentation but it's a simple integration. see kotlin/internal/jvm/android.bzl.
  • Jun 29, 2018. The commits from this date forward are compatible with bazel >=0.14. JDK9 host issues were fixed as well some other deprecations. I recommend skipping 0.15.0 if you are on a Mac.
  • May 25, 2018. Test "friend" support. A single friend dep can be provided to kt_jvm_test which allows the test to access internal members of the module under test.
  • February 15, 2018. Toolchains for the JVM rules. Currently this allow tweaking:
    • The JVM target (bytecode level).
    • API and Language levels.
    • Coroutines, enabled by default.
  • February 9, 2018. Annotation processing.
  • February 5, 2018. JVM rule name change: the prefix has changed from kotlin_ to kt_jvm_.


These rules were initially forked from pubref/rules_kotlin. Key changes:

  • Replace the macros with three basic rules. kt_jvm_binary, kt_jvm_library and kt_jvm_test.
  • Use a single dep attribute instead of java_dep and dep.
  • Add support for the following standard java rules attributes:
    • data
    • resource_jars
    • runtime_deps
    • resources
    • resources_strip_prefix
    • exports
  • Persistent worker support.
  • Mixed-Mode compilation (compile Java and Kotlin in one pass).

Quick Guide

This section just contains a quick overview. Consult the generated documentation. Note: Skydoc documentation is no longer being generated. Comprehensive documentation will have to wait till the new documentation generation tool is ready. A contribution to port the documentation to the RST format like rules_go has would be very welcome !


In the project's WORKSPACE, declare the external repository and initialize the toolchains, like this:

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

rules_kotlin_version = "67f4a6050584730ebae7f8a40435a209f8e0b48e"

    name = "io_bazel_rules_kotlin",
    urls = ["" % rules_kotlin_version],
    type = "zip",
    strip_prefix = "rules_kotlin-%s" % rules_kotlin_version

load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kotlin_repositories", "kt_register_toolchains")

BUILD files

In your project's BUILD files, load the kotlin rules and use them like so:

load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_jvm_library")

    name = "package_name",
    srcs = glob(["*.kt"]),
    deps = [


This project is licensed under the Apache 2.0 license, as are all contributions


See the CONTRIBUTING doc for information about how to contribute to this project.