{"id":47296544,"url":"https://github.com/bazel-contrib/rules_kotlin","last_synced_at":"2026-03-30T21:00:38.936Z","repository":{"id":37251706,"uuid":"119720081","full_name":"bazel-contrib/rules_kotlin","owner":"bazel-contrib","description":"Bazel rules for Kotlin","archived":false,"fork":false,"pushed_at":"2026-03-26T16:52:23.000Z","size":5434,"stargazers_count":361,"open_issues_count":241,"forks_count":252,"subscribers_count":31,"default_branch":"master","last_synced_at":"2026-03-26T17:15:47.288Z","etag":null,"topics":["bazel","bazel-rules","kotlin"],"latest_commit_sha":null,"homepage":"","language":"Starlark","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bazel-contrib.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS","dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"open_collective":"bazel-rules-authors-sig"}},"created_at":"2018-01-31T17:32:03.000Z","updated_at":"2026-03-26T16:50:24.000Z","dependencies_parsed_at":"2026-03-11T17:02:33.425Z","dependency_job_id":null,"html_url":"https://github.com/bazel-contrib/rules_kotlin","commit_stats":null,"previous_names":["bazel-contrib/rules_kotlin"],"tags_count":55,"template":false,"template_full_name":null,"purl":"pkg:github/bazel-contrib/rules_kotlin","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bazel-contrib%2Frules_kotlin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bazel-contrib%2Frules_kotlin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bazel-contrib%2Frules_kotlin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bazel-contrib%2Frules_kotlin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bazel-contrib","download_url":"https://codeload.github.com/bazel-contrib/rules_kotlin/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bazel-contrib%2Frules_kotlin/sbom","scorecard":{"id":227606,"data":{"date":"2025-08-11","repo":{"name":"github.com/bazelbuild/rules_kotlin","commit":"17862f9eaa646401710195fd991f6b9e62647934"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":5.7,"checks":[{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Maintained","score":10,"reason":"30 commit(s) and 10 issue activity found in the last 90 days -- score normalized to 10","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/release.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Code-Review","score":10,"reason":"all changesets reviewed","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:15: update your workflow using https://app.stepsecurity.io/secureworkflow/bazelbuild/rules_kotlin/release.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/bazelbuild/rules_kotlin/release.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:24: update your workflow using https://app.stepsecurity.io/secureworkflow/bazelbuild/rules_kotlin/release.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/release.yml:34: update your workflow using https://app.stepsecurity.io/secureworkflow/bazelbuild/rules_kotlin/release.yml/master?enable=pin","Info:   0 out of   3 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   1 third-party GitHubAction dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: Apache License 2.0: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Signed-Releases","score":0,"reason":"Project has not signed or included provenance with any releases.","details":["Warn: release artifact v2.1.8 not signed: https://api.github.com/repos/bazelbuild/rules_kotlin/releases/227233429","Warn: release artifact v2.1.7 not signed: https://api.github.com/repos/bazelbuild/rules_kotlin/releases/225416768","Warn: release artifact v2.1.6 not signed: https://api.github.com/repos/bazelbuild/rules_kotlin/releases/224119879","Warn: release artifact v2.1.4 not signed: https://api.github.com/repos/bazelbuild/rules_kotlin/releases/215262729","Warn: release artifact v2.1.3 not signed: https://api.github.com/repos/bazelbuild/rules_kotlin/releases/206021043","Warn: release artifact v2.1.8 does not have provenance: https://api.github.com/repos/bazelbuild/rules_kotlin/releases/227233429","Warn: release artifact v2.1.7 does not have provenance: https://api.github.com/repos/bazelbuild/rules_kotlin/releases/225416768","Warn: release artifact v2.1.6 does not have provenance: https://api.github.com/repos/bazelbuild/rules_kotlin/releases/224119879","Warn: release artifact v2.1.4 does not have provenance: https://api.github.com/repos/bazelbuild/rules_kotlin/releases/215262729","Warn: release artifact v2.1.3 does not have provenance: https://api.github.com/repos/bazelbuild/rules_kotlin/releases/206021043"],"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Security-Policy","score":10,"reason":"security policy file detected","details":["Info: security policy file detected: github.com/bazelbuild/.github/SECURITY.md:1","Info: Found linked content: github.com/bazelbuild/.github/SECURITY.md:1","Info: Found disclosure, vulnerability, and/or timelines in security policy: github.com/bazelbuild/.github/SECURITY.md:1","Info: Found text in security policy: github.com/bazelbuild/.github/SECURITY.md:1"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'","Warn: branch protection not enabled for branch 'release-v1.7.0'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"SAST","score":5,"reason":"SAST tool is not run on all commits -- score normalized to 5","details":["Warn: 17 commits out of 30 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-17T04:07:29.289Z","repository_id":37251706,"created_at":"2025-08-17T04:07:29.289Z","updated_at":"2025-08-17T04:07:29.289Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31209945,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-30T15:24:02.938Z","status":"ssl_error","status_checked_at":"2026-03-30T15:23:44.804Z","response_time":138,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bazel","bazel-rules","kotlin"],"created_at":"2026-03-16T17:00:22.272Z","updated_at":"2026-03-30T21:00:38.922Z","avatar_url":"https://github.com/bazel-contrib.png","language":"Starlark","funding_links":["https://opencollective.com/bazel-rules-authors-sig"],"categories":["Starlark"],"sub_categories":[],"readme":"# Bazel Kotlin Rules\n\n[![Build Status](https://badge.buildkite.com/a8860e94a7378491ce8f50480e3605b49eb2558cfa851bbf9b.svg)](https://buildkite.com/bazel/kotlin-postsubmit)\n\u003ca href=\"https://github.com/bazelbuild/rules_kotlin/tree/master\"\u003e\u003cimg src=\"https://img.shields.io/badge/Main%20Branch-master-blue.svg\"/\u003e\u003c/a\u003e\n###  Releases\n\n\u003ca href=\"https://github.com/bazelbuild/rules_kotlin/releases/latest\"\u003e\u003cimg src=\"https://img.shields.io/github/v/release/bazelbuild/rules_kotlin?display_name=tag\u0026label=Latest%20Stable%20Release\"/\u003e\u003c/a\u003e\n\u003cbr/\u003e\n\u003ca href=\"https://github.com/bazelbuild/rules_kotlin/releases/\"\u003e\u003cimg src=\"https://img.shields.io/github/v/release/bazelbuild/rules_kotlin?display_name=tag\u0026include_prereleases\u0026label=Latest%20Release%20Candidate\"/\u003e\u003c/a\u003e\n\nFor more information about release and changelogs please see [Changelog](CHANGELOG.md) or refer to the [Github Releases](https://github.com/bazelbuild/rules_kotlin/releases) page.\n\n# Overview \n\n**rules_kotlin** supports the basic paradigm of `*_binary`, `*_library`, `*_test` of other Bazel \nlanguage rules. It also supports `jvm`, `android`, and `js` flavors, with the prefix `kt_jvm`\nand `kt_android` typically applied to the rules.\n\nSupport for kotlin's -Xfriend-paths via the `associates=` attribute in the jvm allow access to\n`internal` members.\n\nAlso, `kt_jvm_*` rules support the following standard `java_*` rules attributes:\n  * `data`\n  * `resource_jars`\n  * `runtime_deps`\n  * `resources`\n  * `resources_strip_prefix`\n  * `exports`\n\nAdditionally, `kt_jvm_binary` and `kt_jvm_test` support environment variable configuration:\n  * `env` - Dictionary of environment variables to set when the target is executed with `bazel run` or `bazel test`\n  * `env_inherit` - List of environment variable names to inherit from the shell environment\n\nAndroid rules also support custom_package for `R.java` generation, `manifest=`, `resource_files`, etc.\n\nOther features:\n  * Persistent worker support.\n  * Mixed-Mode compilation (compile Java and Kotlin in one pass).\n  * Configurable Kotlinc distribution and version\n  * Configurable Toolchain\n  * Support for all recent major Kotlin releases.\n  \nJavascript is reported to work, but is not as well maintained (at present)\n\n# Documentation\n\nGenerated API documentation is available at\n[https://bazelbuild.github.io/rules_kotlin/kotlin](https://bazelbuild.github.io/rules_kotlin/kotlin).\n\n# Quick Guide\n\n## Installation\nCopy from the\n[release you wish to use](https://github.com/bazelbuild/rules_kotlin/releases) either the Bzlmod or WORKSPACE snippet into your `MODULE.bazel` or `WORKSPACE` file respectively.\n\n### `WORKSPACE`\nIn the project's `WORKSPACE`, declare the external repository and initialize the toolchains, like\nthis:\n\n```python\nload(\"@bazel_tools//tools/build_defs/repo:http.bzl\", \"http_archive\")\n\nrules_kotlin_version = \"1.9.0\"\nrules_kotlin_sha = \"5766f1e599acf551aa56f49dab9ab9108269b03c557496c54acaf41f98e2b8d6\"\nhttp_archive(\n    name = \"rules_kotlin\",\n    urls = [\"https://github.com/bazelbuild/rules_kotlin/releases/download/v%s/rules_kotlin-v%s.tar.gz\" % (rules_kotlin_version, rules_kotlin_version)],\n    sha256 = rules_kotlin_sha,\n)\n\nload(\"@rules_kotlin//kotlin:repositories.bzl\", \"kotlin_repositories\")\nkotlin_repositories() # if you want the default. Otherwise see custom kotlinc distribution below\n\nload(\"@rules_kotlin//kotlin:core.bzl\", \"kt_register_toolchains\")\nkt_register_toolchains() # to use the default toolchain, otherwise see toolchains below\n```\n\n## `BUILD` files\n\nIn your project's `BUILD` files, load the Kotlin rules and use them like so:\n\n```python\nload(\"@rules_kotlin//kotlin:jvm.bzl\", \"kt_jvm_library\")\n\nkt_jvm_library(\n    name = \"package_name\",\n    srcs = glob([\"*.kt\"]),\n    deps = [\n        \"//path/to/dependency\",\n    ],\n)\n```\n\n## Custom toolchain\n\nTo enable a custom toolchain (to configure language level, etc.)\ndo the following.  In a `\u003cworkspace\u003e/BUILD.bazel` file define the following:\n\n```python\nload(\"@rules_kotlin//kotlin:core.bzl\", \"define_kt_toolchain\")\n\ndefine_kt_toolchain(\n    name = \"kotlin_toolchain\",\n    api_version = KOTLIN_LANGUAGE_LEVEL,  # \"1.9\", \"2.0\", \"2.1\", \"2.2\", or \"2.3\"\n    jvm_target = JAVA_LANGUAGE_LEVEL, # \"1.8\", \"9\", \"10\", \"11\", \"12\", \"13\", \"14\", \"15\", \"16\", \"17\", \"18\", \"19\", \"20\", \"21\", \"22\", \"23\", \"24\", or \"25\"\n    language_version = KOTLIN_LANGUAGE_LEVEL,  # \"1.9\", \"2.0\", \"2.1\", \"2.2\", or \"2.3\"\n)\n```\n\nand then in your `WORKSPACE` file, instead of `kt_register_toolchains()` do\n\n```python\nregister_toolchains(\"//:kotlin_toolchain\")\n```\n\n## Custom `kotlinc` distribution (and version)\n\nTo choose a different `kotlinc` distribution (1.3 and 1.4 variants supported), do the following\nin your `WORKSPACE` file (or import from a `.bzl` file:\n\n### `MODULE.bazel`\n```python\nrules_kotlin_extensions = use_extension(\"@rules_kotlin//src/main/starlark/core/repositories:bzlmod_setup.bzl\", \"rules_kotlin_extensions\")\nrules_kotlin_extensions.kotlinc_version(\n    version = \"2.1.20\",\n    sha256 = \"a118197b0de55ffab2bc8d5cd03a5e39033cfb53383d6931bc761dec0784891a\"\n)\nuse_repo(rules_kotlin_extensions, \"com_github_google_ksp\", \"com_github_jetbrains_kotlin\", \"com_github_jetbrains_kotlin_git\", \"com_github_pinterest_ktlint\", \"kotlinx_serialization_core_jvm\", \"kotlinx_serialization_json\", \"kotlinx_serialization_json_jvm\")\n```\n\n### `WORKSPACE`\n```python\nload(\"@rules_kotlin//kotlin:repositories.bzl\", \"kotlin_repositories\", \"kotlinc_version\")\n\nkotlin_repositories(\n    compiler_release = kotlinc_version(\n        release = \"2.1.20\",\n        sha256 = \"a118197b0de55ffab2bc8d5cd03a5e39033cfb53383d6931bc761dec0784891a\"\n    )\n)\n```\n\n## Third party dependencies \n_(e.g. Maven artifacts)_\n\nThird party (external) artifacts can be brought in with systems such as [`rules_jvm_external`](https://github.com/bazelbuild/rules_jvm_external) or [`bazel_maven_repository`](https://github.com/square/bazel_maven_repository) or [`bazel-deps`](https://github.com/johnynek/bazel-deps), but make sure the version you use doesn't naively use `java_import`, as this will cause bazel to make an interface-only (`ijar`), or ABI jar, and the native `ijar` tool does not know about kotlin metadata with respect to inlined functions, and will remove method bodies inappropriately.  Recent versions of `rules_jvm_external` and `bazel_maven_repository` are known to work with Kotlin.\n\n## Development Setup\n\nFor local development of rules_kotlin:\n\n#### With Bzlmod\n\n```python\nlocal_path_override(\n    module_name = \"rules_kotlin\",\n    path = \"../path/to/rules_kotlin_clone/\",\n)\n```\n\n#### From HEAD (Bzlmod)\n\n```python\n_RULES_KOTLIN_COMMIT = \"HEAD_COMMIT_SHA\"\n\narchive_override(\n    module_name = \"rules_kotlin\",\n    integrity = \"sha256-...\",\n    strip_prefix = \"rules_kotlin-%s\" % _RULES_KOTLIN_COMMIT,\n    urls = [\"https://github.com/bazelbuild/rules_kotlin/archive/%s.tar.gz\" % _RULES_KOTLIN_COMMIT],\n)\n```\n\n# Debugging native actions\n\nTo attach debugger and step through native action code when using local checkout of rules_kotlin repo :\n\n1. Open `rules_kotlin` project in Android Studio, using existing `.bazelproject` file as project view.\n2. In terminal, build the kotlin target you want to debug, using the subcommand option, ex: `bazel build //lib/mylib:main_kt -s`. You can also use `bazel aquery` to get this info.\n3. Locate the subcommand for the kotlin action you want to debug, let's say `KotlinCompile`. Note: If you don't see it, target rebuild may have been skipped (in this case `touch` one of the source .kt file to trigger rebuild).\n4. Export `REPOSITORY_NAME` as specified in action env, ex : `export REPOSITORY_NAME=rules_kotlin`\n5. Copy the command line, ex : `bazel-out/darwin_arm64-opt-exec-2B5CBBC6/bin/external/rules_kotlin/src/main/kotlin/build '--flagfile=bazel-out/darwin_arm64-fastbuild/bin/lib/mylib/main_kt-kt.jar-0.params'`\n6. Change directory into the [execRoot](https://bazel.build/remote/output-directories#layout-diagram), normally `bazel-MYPROJECT`, available via `bazel info | grep execution_root`.\n7. Add `--debug=5005` to command line to make the action wait for a debugger to attach, ex: `bazel-out/darwin_arm64-opt-exec-2B5CBBC6/bin/external/rules_kotlin/src/main/kotlin/build --debug=5005 '--flagfile=bazel-out/darwin_arm64-fastbuild/bin/lib/mylib/main_kt-kt.jar-0.params'`. Note: if command invokes `java` toolchain directly, use `-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005` instead.\n8. You should see in output that action is waiting for debugger. Use a default `Remote JVM Debug` configuration in Android Studio, set breakpoint in kotlin action java/kt code, and attach debugger. Breakpoints should be hit.\n\n# Kotlin and Java compiler flags\n\nThe `kt_kotlinc_options` and `kt_javac_options` rules allows passing compiler flags to kotlinc and javac.\n\nNote: Not all compiler flags are supported in all language versions. When this happens, the rules will fail.\n\nFor example you can define global compiler flags by doing: \n```python\nload(\"@rules_kotlin//kotlin:core.bzl\", \"kt_kotlinc_options\", \"kt_javac_options\", \"define_kt_toolchain\")\n\nkt_kotlinc_options(\n    name = \"kt_kotlinc_options\",\n    x_no_param_assertions = True,\n    jvm_target = \"1.8\",\n)\n\nkt_javac_options(\n    name = \"kt_javac_options\",\n    warn = \"off\",\n)\n\ndefine_kt_toolchain(\n    name = \"kotlin_toolchain\",\n    kotlinc_options = \"//:kt_kotlinc_options\",\n    javac_options = \"//:kt_javac_options\",\n)\n```\n\nYou can optionally override compiler flags at the target level by providing an alternative set of `kt_kotlinc_options` or `kt_javac_options` in your target definitions.\n\nCompiler flags that are passed to the rule definitions will be taken over the toolchain definition.\n\nExample:\n```python\nload(\"@rules_kotlin//kotlin:core.bzl\", \"kt_kotlinc_options\", \"kt_javac_options\")\nload(\"@rules_kotlin//kotlin:jvm.bzl\", \"kt_jvm_library\")\n\nkt_kotlinc_options(\n    name = \"kt_kotlinc_options_for_package_name\",\n    x_no_param_assertions = True,\n    x_optin = [\n        \"kotlin.Experimental\",\n        \"kotlin.ExperimentalStdlibApi\",\n    ],\n)\n\nkt_javac_options(\n    name = \"kt_javac_options_for_package_name\",\n    warn = \"off\"\n)\n\nkt_jvm_library(\n    name = \"package_name\",\n    srcs = glob([\"*.kt\"]),\n    kotlinc_opts = \"//:kt_kotlinc_options_for_package_name\",\n    javac_opts = \"//:kt_javac_options_for_package_name\",\n    deps = [\"//path/to/dependency\"],\n)\n```\n\n### Lambda Bytecode Generation\n\nNote: `kt_kotlinc_options` defaults `x_lambdas` and `x_sam_conversions` to `\"class\"`, which differs from Kotlin 2.x and Gradle's default of `\"indy\"` (invokedynamic). If you encounter issues with bytecode analysis tools expecting invokedynamic-based lambdas, configure these options:\n\n```python\nkt_kotlinc_options(\n    name = \"kt_kotlinc_options\",\n    x_lambdas = \"indy\",\n    x_sam_conversions = \"indy\",\n)\n```\n\nAdditionally, you can add options for both tracing and timing of the bazel build using the `kt_trace` and `kt_timings` flags, for example:\n* `bazel build --define=kt_trace=1`\n* `bazel build --define=kt_timings=1`\n\n`kt_trace=1` will allow you to inspect the full kotlinc commandline invocation, while `kt_timings=1` will report the high level time taken for each step.\n\n# Build Tools API\n\nThe Build Tools API is a modern compilation interface provided by JetBrains for invoking the Kotlin compiler. It offers better integration and is required for incremental compilation support.\n\n**This feature is enabled by default.**\n\nTo disable the Build Tools API and use the legacy compilation approach, add the following flag to your build:\n\n```bash\nbazel build --@rules_kotlin//kotlin/settings:experimental_build_tools_api=false //your:target\n```\n\nOr add it to your `.bazelrc` file:\n\n```\nbuild --@rules_kotlin//kotlin/settings:experimental_build_tools_api=false\n```\n\n# KSP (Kotlin Symbol Processing)\n\nKSP is officially supported as of `rules_kotlin` 1.8 and can be declared using the new\n`kt_ksp_plugin` rule. \n\n```python\nload(\"@rules_kotlin//kotlin:core.bzl\", \"kt_ksp_plugin\")\nload(\"@rules_kotlin//kotlin:jvm.bzl\", \"kt_jvm_library\")\n\nkt_ksp_plugin(\n    name = \"moshi-kotlin-codegen\",\n    processor_class = \"com.squareup.moshi.kotlin.codegen.ksp.JsonClassSymbolProcessorProvider\",\n    deps = [\n        \"@maven//:com_squareup_moshi_moshi\",\n        \"@maven//:com_squareup_moshi_moshi_kotlin\",\n        \"@maven//:com_squareup_moshi_moshi_kotlin_codegen\",\n    ],\n)\n\nkt_jvm_library(\n    name = \"lib\",\n    srcs = glob([\"*.kt\"]),\n    plugins = [\"//:moshi-kotlin-codegen\"],\n)\n```\n\nTo choose a different `ksp_version` distribution,\ndo the following in your repository.\n\n### `MODULE.bazel`\n```python\nrules_kotlin_extensions = use_extension(\"@rules_kotlin//src/main/starlark/core/repositories:bzlmod_setup.bzl\", \"rules_kotlin_extensions\")\nrules_kotlin_extensions.ksp_version(\n    version = \"1.8.22-1.0.11\",\n    sha256 = \"2ce5a08fddd20ef07ac051615905453fe08c3ba3ce5afa5dc43a9b77aa64507d\",\n)\nuse_repo(rules_kotlin_extensions, \"com_github_google_ksp\", \"com_github_jetbrains_kotlin\", \"com_github_jetbrains_kotlin_git\", \"com_github_pinterest_ktlint\", \"kotlinx_serialization_core_jvm\", \"kotlinx_serialization_json\", \"kotlinx_serialization_json_jvm\")\n```\n\n### `WORKSPACE` (or import from a `.bzl` file):\n\n```python\nload(\"@rules_kotlin//kotlin:repositories.bzl\", \"kotlin_repositories\", \"ksp_version\")\n\nkotlin_repositories(\n    ksp_compiler_release = ksp_version(\n        release = \"1.8.22-1.0.11\",\n        sha256 = \"2ce5a08fddd20ef07ac051615905453fe08c3ba3ce5afa5dc43a9b77aa64507d\",\n    ),\n)\n```\n\n# Kotlin compiler plugins\n\nThe `kt_compiler_plugin` rule allows running Kotlin compiler plugins, such as no-arg, sam-with-receiver and allopen.\n\nFor example, you can add allopen to your project like this:\n```python\nload(\"@rules_kotlin//kotlin:core.bzl\", \"kt_compiler_plugin\")\nload(\"@rules_kotlin//kotlin:jvm.bzl\", \"kt_jvm_library\")\n\nkt_compiler_plugin(\n    name = \"open_for_testing_plugin\",\n    id = \"org.jetbrains.kotlin.allopen\",\n    options = {\n        \"annotation\": \"plugin.allopen.OpenForTesting\",\n    },\n    deps = [\n        \"//kotlin/compiler:allopen-compiler-plugin\",\n    ],\n)\n\nkt_jvm_library(\n    name = \"user\",\n    srcs = [\"User.kt\"], # The User class is annotated with OpenForTesting\n    plugins = [\n        \":open_for_testing_plugin\",\n    ],\n    deps = [\n        \":open_for_testing\", # This contains the annotation (plugin.allopen.OpenForTesting)\n    ],\n)\n```\n\nFull examples of using compiler plugins can be found [here](examples/plugin).\n\n## Creating Rule Releases\n\nA new release can be published by just pushing a tag.\n\nOnce the tag is pushed, GitHub Actions will build, test, and publish a release to both GitHub releases and the BCR.\n\nA tag can be created and pushed by doing the following:\n```\ngit tag v4.13\ngit push origin v4.13\n```\n\n\n## Examples\n\nExamples can be found in the [examples directory](https://github.com/bazelbuild/rules_kotlin/tree/master/examples), including usage with Android, Dagger, Node-JS, Kotlin compiler plugins, etc.\n\n# History\n\nThese rules were initially forked from [pubref/rules_kotlin](http://github.com/pubref/rules_kotlin), and then re-forked from [bazelbuild/rules_kotlin](http://github.com/bazelbuild/rules_kotlin). They were merged back into this repository in October, 2019.\n\n# License\n\nThis project is licensed under the [Apache 2.0 license](LICENSE), as are all contributions\n\n# Contributing\n\nSee the [CONTRIBUTING](CONTRIBUTING.md) doc for information about how to contribute to\nthis project.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbazel-contrib%2Frules_kotlin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbazel-contrib%2Frules_kotlin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbazel-contrib%2Frules_kotlin/lists"}