Skip to content
Bazel rules for Kotlin
Branch: legacy_continu…
Clone or download
Pull request Compare This branch is 27 commits ahead of bazelbuild:master.
cgruber Merge pull request #15 from cgruber/quiesce_module_warnings
Quiesce Java9+ module warnings about reflective access
Latest commit ecc8957 Jul 2, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
.bazelci Don't test on Ubuntu 14.04 (bazelbuild#183) May 30, 2019
docs remove skydoc generation wireup Aug 12, 2018
examples Upgrade the coffee app and move coroutines to the released, non-exper… Jun 13, 2019
scripts support only a single compiler repository version Sep 3, 2018
src Quiesce Java9+ module warnings about reflective access, as these are … Jul 2, 2019
third_party Use the more modern instead of the deprecated ctx.a… Jun 21, 2019
.bazelproject consolate all srcs under src Aug 17, 2018
.gitignore Have the no-srcs android_library in android.bzl use exports= instead … Mar 20, 2019
AUTHORS Update AUTHORS Jan 31, 2018
BUILD consolate all srcs under src Aug 17, 2018
CODEOWNERS Create CODEOWNERS (bazelbuild#171) Feb 1, 2019 initial import from hsyed/rules_kotlin Jan 31, 2018
CONTRIBUTORS initial import from hsyed/rules_kotlin Jan 31, 2018
LICENSE initial import from hsyed/rules_kotlin Jan 31, 2018
Makefile add builder tests for annotation processing Aug 20, 2018 Update for release legacy-modded-0.26.1-02 Jun 21, 2019 Create Apr 2, 2019
WORKSPACE Update deps for 0.26.0. (bazelbuild#191) May 30, 2019
renovate.json Add renovate.json (bazelbuild#176) Mar 20, 2019

Build Status

A fork of the legacy branch of bazelbuild/rules_kotlin

Current release: legacy_modded-0_26_1-02 Maintained branch: legacy_continued


  • June 20, 2019. Fix to support 0.27.0 and release of legacy_modded-0_26_1-02
    • Serious reconsideration of the version naming scheme...
  • June 12, 2019. Kotlin 1.3 support, and release of legacy_modded-0_26_1-01
  • June 11, 2019. Fix to kotlin worker to allow modern dagger to be used in kapt. (worker was leaking its dagger dep)
  • May 17, 2019. More changes from upstream (mostly fixes for bazel version bump) and releases from the fork
  • April 1, 2019. Roadmap for rules_kotlin published. The cgruber fork will continue until the legacy branch in the parent repo can be updated (or no one needs the fork)
  • February 20, 2019. Future directions of rules_kotlin.
  • October 24, 2018. Christian Gruber forks the main kotlin rules repository, adding in two fixes.
  • 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, and then re-forked from bazelbuild/rules_kotlin

Key changes:

  • Replace the macros with three basic rules. kt_jvm_binary, kt_jvm_library and kt_jvm_test.
  • Android rules. kt_android_library and kt_android_binary
  • Friend support for tests (supports access to internal types and functions)
  • Use a single deps 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).
  • Configurable Kotlinc distribtution and verison
  • Configurable Toolchain
  • Kotlin 1.3 support

Quick Guide


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 = "legacy-modded-0_26_1-02"
rules_kotlin_sha = "245d0bc1511048aaf82afd0fa8a83e8c3b5afdff0ae4fbcae25e03bb2c6f1a1a"
    name = "io_bazel_rules_kotlin",
    urls = ["" % rules_kotlin_version],
    type = "zip",
    strip_prefix = "rules_kotlin-%s" % rules_kotlin_version,
    sha256 = rules_kotlin_sha,

load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kotlin_repositories", "kt_register_toolchains")
kotlin_repositories() # if you want the default. Otherwise see custom kotlinc distribution below
kt_register_toolchains() # to use the default toolchain, otherwise see toolchains below

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 = [

Custom toolchain

To enable a custom toolchain (to configure language level, etc.) do the following. In a <workspace>/BUILD.bazel file define the following:

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

    name = "kotlin_toolchain",
    api_version = KOTLIN_LANGUAGE_LEVEL,  # "1.1", "1.2", or "1.3"
    jvm_target = JAVA_LANGUAGE_LEVEL, # "1.6" or "1.8"
    language_version = KOTLIN_LANGUAGE_LEVEL,  # "1.1", "1.2", or "1.3"

and then in your WORKSPACE file, instead of kt_register_toolchains() do


Custom kotlinc distribution (and version)

To choose a different kotlinc distribution (only 1.3 variants supported), do the following in your WORKSPACE file (or import from a .bzl file:

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

KOTLINC_RELEASE_SHA = "107325d56315af4f59ff28db6837d03c2660088e3efeb7d4e41f3e01bb848d6a"

    "urls": [
        "{v}/kotlin-compiler-{v}.zip".format(v = KOTLIN_VERSION),
    "sha256": KOTLINC_RELEASE_SHA,

kotlin_repositories(compiler_release = KOTLINC_RELEASE)


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.

You can’t perform that action at this time.