Skip to content

Configuring custom toolchain doesn't work as expected #1294

Open
@brettchabot

Description

@brettchabot

I've upgraded my project to use rules_kotlin 2.1.3 with bazel 7.5.0 /bzlmod.

I want to pin my project to kotlin 1.9. I'm trying to configure a custom toolchain by defining the following target in the root BUILD file:

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

define_kt_toolchain(
    name = "kotlin_toolchain",
    api_version ="1.9",
    language_version = "1.9",
) 

With the following logic in MODULE.bazel and/or WORKSPACE (I've tried both)

register_toolchains("//:kotlin_toolchain")

I'm still unexpectedly able to use kotlin stdlib APIs and language features from 2.0+.

Am I doing something wrong?

Repro:

  1. clone Demo using a kotlin 2.0 feature android/android-test#2380
  2. bazelisk build //services/shellexecutor/java/androidx/test/services/shellexecutor:local_socket_protocol

Expected results:
Compile would fail since string.toCharArray was added in kotlin 2.0

Observed result:
Compile succeeds

I've also tried other kotlin 2.0+ features with similar results.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions