Bazel Configuration | Requirements | Windows-specific information
A minimal, professional template demonstrating how to configure Bazel to build, run and debug Kotlin code (using the IntelliJ IDEA IDE with the official Bazel plugin).
.
├── MODULE.bazel # Bzlmod configuration
├── .bazelrc # Bazel runtime configuration
├── .bazelversion # Pinned Bazel version
├── BUILD.bazel # Kotlin toolchain definition
└── src/
├── BUILD.bazel # Build targets definition
├── main/
├── java/
│ └── org/
│ └── example/
│ └── Main.java # Entry point (necessary for MS Windows)
└── kotlin/
└── org/
└── example/
└── FileUtil.kt # Kotlin utility class
This project demonstrates modern Bazel configuration with Bzlmod:
- Uses Bzlmod for dependency management (Bazel's module system)
- Depends on
rules_kotlin
version 2.1.8 for Kotlin support - Configures Maven repositories for external dependencies
- Registers a custom Kotlin toolchain
- Sets Java language version to 17 and runtime to JDK 21
- Enables Windows-specific configuration with
--legacy_external_runfiles
- Contains workarounds for known issues with
rules_kotlin
on MS Windows
- Defines Kotlin toolchain with language and API version 2.0
- Sets JVM target to 17
- Configures Kotlin compiler options
- Defines three targets:
main_lib
: Java library containing Main.javautils_lib
: Kotlin library containing FileUtil.ktMain
: Java binary with the main classorg.example.Main
- Uses Java binary wrapper instead of
kt_jvm_binary
for Windows compatibility
The example demonstrates Java-Kotlin interoperability (due to known Windows-specific issues when it comes to debugging):
- Java entry point (
Main.java
) calls Kotlin utility class - Kotlin utility (
FileUtil.kt
) provides file extension extraction functionality
Build the application:
bazel build //src:Main
Run the application:
bazel run //src:Main
Expected output:
The file extension is: .txt
- Bazel 8.x (use
bazelisk
for version management)- For Windows, it is recommended to install Bazelisk
through Chocolatey:
choco install bazelisk
- For Windows, it is recommended to install Bazelisk
through Chocolatey:
- Optional: IntelliJ IDEA with Bazel plugin
Running Bazel on Windows requires at the time of writing a few workarounds:
- Use Java binary wrapper instead of
kt_jvm_binary
- The
kt_jvm_binary
rule does not (at this moment) support debugging (with IntelliJ) on Windows
- The
- Set
--legacy_external_runfiles
to avoid issues with runfiles- It is known that on Windows runfiles are not properly resolved and this error is thrown
LAUNCHER ERROR: Rlocation failed on _main/external/rules_kotlin++rules_kotlin_extensions+com_github_jetbrains_kotlin_git/lib/annotations-13.0.jar, path doesn't exist in MANIFEST file
- It is known that on Windows runfiles are not properly resolved and this error is thrown
This repository contains a GitHub Actions workflow
that builds the source code on Windows, Linux,
and macOS.
It should provide a good starting point for CI/CD pipelines utilizing Bazel with Kotlin.
The workflow is not complete and must be extended to include testing and deployment steps
that make sense for your project.
Licensed under the BSD 3-Clause License http://opensource.org/licenses/bsd-3-clause. This project may not be copied, modified, or distributed except according to those terms.