Public Kotlin/JVM rule API.
load("@rules_kotlin//kotlin:jvm.bzl", "kt_javac_options") kt_javac_options(<a href="#kt_javac_options-name">name</a>, <a href="#kt_javac_options-add_exports">add_exports</a>, <a href="#kt_javac_options-no_proc">no_proc</a>, <a href="#kt_javac_options-release">release</a>, <a href="#kt_javac_options-warn">warn</a>, <a href="#kt_javac_options-x_ep_disable_all_checks">x_ep_disable_all_checks</a>, <a href="#kt_javac_options-x_explicit_api_mode">x_explicit_api_mode</a>, <a href="#kt_javac_options-x_lint">x_lint</a>, <a href="#kt_javac_options-xd_suppress_notes">xd_suppress_notes</a>)
Define java compiler options for kt_jvm_* rules with java sources.
ATTRIBUTES
load("@rules_kotlin//kotlin:jvm.bzl", "kt_jvm_binary") kt_jvm_binary(<a href="#kt_jvm_binary-name">name</a>, <a href="#kt_jvm_binary-deps">deps</a>, <a href="#kt_jvm_binary-srcs">srcs</a>, <a href="#kt_jvm_binary-data">data</a>, <a href="#kt_jvm_binary-resources">resources</a>, <a href="#kt_jvm_binary-associates">associates</a>, <a href="#kt_jvm_binary-env">env</a>, <a href="#kt_jvm_binary-env_inherit">env_inherit</a>, <a href="#kt_jvm_binary-java_stub_template">java_stub_template</a>, <a href="#kt_jvm_binary-javac_opts">javac_opts</a>, <a href="#kt_jvm_binary-jvm_flags">jvm_flags</a>, <a href="#kt_jvm_binary-kotlinc_opts">kotlinc_opts</a>, <a href="#kt_jvm_binary-main_class">main_class</a>, <a href="#kt_jvm_binary-module_name">module_name</a>, <a href="#kt_jvm_binary-plugins">plugins</a>, <a href="#kt_jvm_binary-resource_jars">resource_jars</a>, <a href="#kt_jvm_binary-resource_strip_prefix">resource_strip_prefix</a>, <a href="#kt_jvm_binary-runtime_deps">runtime_deps</a>)
Builds a Java archive (“jar file”), plus a wrapper shell script with the same name as the rule. The wrapper shell script uses a classpath that includes, among other things, a jar file for each library on which the binary depends.
Note: This rule does not have all of the features found in java_binary. It is appropriate for building workspace utilities. java_binary should be preferred for release artefacts.
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| deps | A list of dependencies of this rule.See general comments about deps at Attributes common to all build rules. | List of labels | optional | [] |
| srcs | The list of source files that are processed to create the target, this can contain both Java and Kotlin files. Java analysis occurs first so Kotlin classes may depend on Java classes in the same compilation unit. | List of labels | optional | [] |
| data | The list of files needed by this rule at runtime. See general comments about data at Attributes common to all build rules. | List of labels | optional | [] |
| resources | A list of files that should be include in a Java jar. | List of labels | optional | [] |
| associates | Kotlin deps who should be considered part of the same module/compilation-unit for the purposes of “internal” access. Such deps must all share the same module space and so a target cannot associate to two deps from two different modules. | List of labels | optional | [] |
| env | Environment variables to set when this binary is executed with bazel run. Subject to $(location) and “Make variable” substitution. | Dictionary: String -> String | optional | {} |
| env_inherit | Names of environment variables to inherit from the shell when executed with bazel run. | List of strings | optional | [] |
| java_stub_template | - | Label | optional | "@rules_kotlin//third_party:java_stub_template.txt" |
| javac_opts | Javac options to be used when compiling this target. These opts if provided will be used instead of the ones provided to the toolchain. | Label | optional | None |
| jvm_flags | A list of flags to embed in the wrapper script generated for running this binary. Note: does not yet support make variable substitution. | List of strings | optional | [] |
| kotlinc_opts | Kotlinc options to be used when compiling this target. These opts if provided will be used instead of the ones provided to the toolchain. | Label | optional | None |
| main_class | Name of class with main() method to use as entry point. | String | required | |
| module_name | The name of the module, if not provided the module name is derived from the label. --e.g., //some/package/path:label_name is translated to some_package_path-label_name. | String | optional | "" |
| plugins | - | List of labels | optional | [] |
| resource_jars | Set of archives containing Java resources. If specified, the contents of these jars are merged into the output jar. | List of labels | optional | [] |
| resource_strip_prefix | The path prefix to strip from Java resources. Should be a label pointing to a directory. Files residing under common prefix such as src/main/resources or src/test/resources or kotlin will have stripping applied by convention if this is not specified. | Label | optional | None |
| runtime_deps | Libraries to make available to the final binary or test at runtime only. Like ordinary deps, these will appear on the runtime classpath, but unlike them, not on the compile-time classpath. | List of labels | optional | [] |
load("@rules_kotlin//kotlin:jvm.bzl", "kt_jvm_import") kt_jvm_import(<a href="#kt_jvm_import-name">name</a>, <a href="#kt_jvm_import-deps">deps</a>, <a href="#kt_jvm_import-exported_compiler_plugins">exported_compiler_plugins</a>, <a href="#kt_jvm_import-exports">exports</a>, <a href="#kt_jvm_import-jar">jar</a>, <a href="#kt_jvm_import-jars">jars</a>, <a href="#kt_jvm_import-neverlink">neverlink</a>, <a href="#kt_jvm_import-runtime_deps">runtime_deps</a>, <a href="#kt_jvm_import-srcjar">srcjar</a>)
Import Kotlin jars.
# Old style usage -- reference file groups, do not used this. kt_jvm_import( name = "kodein", jars = [ "@com_github_salomonbrys_kodein_kodein//jar:file", "@com_github_salomonbrys_kodein_kodein_core//jar:file" ] ) # This style will pull in the transitive runtime dependencies of the targets as well. kt_jvm_import( name = "kodein", jars = [ "@com_github_salomonbrys_kodein_kodein//jar", "@com_github_salomonbrys_kodein_kodein_core//jar" ] ) # Import a single kotlin jar. kt_jvm_import( name = "kotlin-stdlib", jars = ["lib/kotlin-stdlib.jar"], srcjar = "lib/kotlin-stdlib-sources.jar" )
ATTRIBUTES
load("@rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library") kt_jvm_library(<a href="#kt_jvm_library-name">name</a>, <a href="#kt_jvm_library-deps">deps</a>, <a href="#kt_jvm_library-srcs">srcs</a>, <a href="#kt_jvm_library-data">data</a>, <a href="#kt_jvm_library-resources">resources</a>, <a href="#kt_jvm_library-associates">associates</a>, <a href="#kt_jvm_library-exported_compiler_plugins">exported_compiler_plugins</a>, <a href="#kt_jvm_library-exports">exports</a>, <a href="#kt_jvm_library-java_stub_template">java_stub_template</a>, <a href="#kt_jvm_library-javac_opts">javac_opts</a>, <a href="#kt_jvm_library-kotlinc_opts">kotlinc_opts</a>, <a href="#kt_jvm_library-module_name">module_name</a>, <a href="#kt_jvm_library-neverlink">neverlink</a>, <a href="#kt_jvm_library-plugins">plugins</a>, <a href="#kt_jvm_library-resource_jars">resource_jars</a>, <a href="#kt_jvm_library-resource_strip_prefix">resource_strip_prefix</a>, <a href="#kt_jvm_library-runtime_deps">runtime_deps</a>)
This rule compiles and links Kotlin and Java sources into a .jar file.
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| deps | A list of dependencies of this rule.See general comments about deps at Attributes common to all build rules. | List of labels | optional | [] |
| srcs | The list of source files that are processed to create the target, this can contain both Java and Kotlin files. Java analysis occurs first so Kotlin classes may depend on Java classes in the same compilation unit. | List of labels | optional | [] |
| data | The list of files needed by this rule at runtime. See general comments about data at Attributes common to all build rules. | List of labels | optional | [] |
| resources | A list of files that should be include in a Java jar. | List of labels | optional | [] |
| associates | Kotlin deps who should be considered part of the same module/compilation-unit for the purposes of “internal” access. Such deps must all share the same module space and so a target cannot associate to two deps from two different modules. | List of labels | optional | [] |
| exported_compiler_plugins | Exported compiler plugins. Compiler plugins listed here will be treated as if they were added in the plugins attribute of any targets that directly depend on this target. Like java_plugins exported_plugins, this is not transitive | List of labels | optional | [] |
| exports | Exported libraries. Deps listed here will be made available to other rules, as if the parents explicitly depended on these deps. This is not true for regular (non-exported) deps. | List of labels | optional | [] |
| java_stub_template | - | Label | optional | "@rules_kotlin//third_party:java_stub_template.txt" |
| javac_opts | Javac options to be used when compiling this target. These opts if provided will be used instead of the ones provided to the toolchain. | Label | optional | None |
| kotlinc_opts | Kotlinc options to be used when compiling this target. These opts if provided will be used instead of the ones provided to the toolchain. | Label | optional | None |
| module_name | The name of the module, if not provided the module name is derived from the label. --e.g., //some/package/path:label_name is translated to some_package_path-label_name. | String | optional | "" |
| neverlink | If true only use this library for compilation and not at runtime. | Boolean | optional | False |
| plugins | - | List of labels | optional | [] |
| resource_jars | Set of archives containing Java resources. If specified, the contents of these jars are merged into the output jar. | List of labels | optional | [] |
| resource_strip_prefix | The path prefix to strip from Java resources. Should be a label pointing to a directory. Files residing under common prefix such as src/main/resources or src/test/resources or kotlin will have stripping applied by convention if this is not specified. | Label | optional | None |
| runtime_deps | Libraries to make available to the final binary or test at runtime only. Like ordinary deps, these will appear on the runtime classpath, but unlike them, not on the compile-time classpath. | List of labels | optional | [] |
load("@rules_kotlin//kotlin:jvm.bzl", "kt_jvm_test") kt_jvm_test(<a href="#kt_jvm_test-name">name</a>, <a href="#kt_jvm_test-deps">deps</a>, <a href="#kt_jvm_test-srcs">srcs</a>, <a href="#kt_jvm_test-data">data</a>, <a href="#kt_jvm_test-resources">resources</a>, <a href="#kt_jvm_test-associates">associates</a>, <a href="#kt_jvm_test-env">env</a>, <a href="#kt_jvm_test-env_inherit">env_inherit</a>, <a href="#kt_jvm_test-java_stub_template">java_stub_template</a>, <a href="#kt_jvm_test-javac_opts">javac_opts</a>, <a href="#kt_jvm_test-jvm_flags">jvm_flags</a>, <a href="#kt_jvm_test-kotlinc_opts">kotlinc_opts</a>, <a href="#kt_jvm_test-main_class">main_class</a>, <a href="#kt_jvm_test-module_name">module_name</a>, <a href="#kt_jvm_test-plugins">plugins</a>, <a href="#kt_jvm_test-resource_jars">resource_jars</a>, <a href="#kt_jvm_test-resource_strip_prefix">resource_strip_prefix</a>, <a href="#kt_jvm_test-runtime_deps">runtime_deps</a>, <a href="#kt_jvm_test-test_class">test_class</a>)
Setup a simple kotlin_test.
Notes:
@rules_kotlin//kotlin/compiler:kotlin-test.ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| deps | A list of dependencies of this rule.See general comments about deps at Attributes common to all build rules. | List of labels | optional | [] |
| srcs | The list of source files that are processed to create the target, this can contain both Java and Kotlin files. Java analysis occurs first so Kotlin classes may depend on Java classes in the same compilation unit. | List of labels | optional | [] |
| data | The list of files needed by this rule at runtime. See general comments about data at Attributes common to all build rules. | List of labels | optional | [] |
| resources | A list of files that should be include in a Java jar. | List of labels | optional | [] |
| associates | Kotlin deps who should be considered part of the same module/compilation-unit for the purposes of “internal” access. Such deps must all share the same module space and so a target cannot associate to two deps from two different modules. | List of labels | optional | [] |
| env | Specifies additional environment variables to set when the target is executed by bazel test. Subject to $(location) and “Make variable” substitution. | Dictionary: String -> String | optional | {} |
| env_inherit | Environment variables to inherit from the external environment. | List of strings | optional | [] |
| java_stub_template | - | Label | optional | "@rules_kotlin//third_party:java_stub_template.txt" |
| javac_opts | Javac options to be used when compiling this target. These opts if provided will be used instead of the ones provided to the toolchain. | Label | optional | None |
| jvm_flags | A list of flags to embed in the wrapper script generated for running this binary. Note: does not yet support make variable substitution. | List of strings | optional | [] |
| kotlinc_opts | Kotlinc options to be used when compiling this target. These opts if provided will be used instead of the ones provided to the toolchain. | Label | optional | None |
| main_class | - | String | optional | "com.google.testing.junit.runner.BazelTestRunner" |
| module_name | The name of the module, if not provided the module name is derived from the label. --e.g., //some/package/path:label_name is translated to some_package_path-label_name. | String | optional | "" |
| plugins | - | List of labels | optional | [] |
| resource_jars | Set of archives containing Java resources. If specified, the contents of these jars are merged into the output jar. | List of labels | optional | [] |
| resource_strip_prefix | The path prefix to strip from Java resources. Should be a label pointing to a directory. Files residing under common prefix such as src/main/resources or src/test/resources or kotlin will have stripping applied by convention if this is not specified. | Label | optional | None |
| runtime_deps | Libraries to make available to the final binary or test at runtime only. Like ordinary deps, these will appear on the runtime classpath, but unlike them, not on the compile-time classpath. | List of labels | optional | [] |
| test_class | The Java class to be loaded by the test runner. | String | optional | "" |
Public ktlint rules.
load("@rules_kotlin//kotlin:lint.bzl", "ktlint_config") ktlint_config(<a href="#ktlint_config-name">name</a>, <a href="#ktlint_config-android_rules_enabled">android_rules_enabled</a>, <a href="#ktlint_config-editorconfig">editorconfig</a>, <a href="#ktlint_config-experimental_rules_enabled">experimental_rules_enabled</a>)
Used to configure ktlint.
ktlint can be configured to use a .editorconfig, as documented at https://github.com/pinterest/ktlint/#editorconfig
ATTRIBUTES
load("@rules_kotlin//kotlin:lint.bzl", "ktlint_fix") ktlint_fix(<a href="#ktlint_fix-name">name</a>, <a href="#ktlint_fix-srcs">srcs</a>, <a href="#ktlint_fix-config">config</a>)
Lint Kotlin files and automatically fix them as needed
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| srcs | Source files to review and fix | List of labels | required | |
| config | ktlint_config to use | Label | optional | None |
load("@rules_kotlin//kotlin:lint.bzl", "ktlint_test") ktlint_test(<a href="#ktlint_test-name">name</a>, <a href="#ktlint_test-srcs">srcs</a>, <a href="#ktlint_test-config">config</a>)
Lint Kotlin files, and fail if the linter raises errors.
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| srcs | Source files to lint | List of labels | required | |
| config | ktlint_config to use | Label | optional | None |
Core Kotlin rule and providers.
load("@rules_kotlin//kotlin:core.bzl", "kt_btapi_runtime") kt_btapi_runtime(<a href="#kt_btapi_runtime-name">name</a>, <a href="#kt_btapi_runtime-base">base</a>, <a href="#kt_btapi_runtime-build_tools_impl">build_tools_impl</a>, <a href="#kt_btapi_runtime-compiler">compiler</a>, <a href="#kt_btapi_runtime-jdeps_gen">jdeps_gen</a>, <a href="#kt_btapi_runtime-jvm_abi_gen">jvm_abi_gen</a>, <a href="#kt_btapi_runtime-kapt">kapt</a>, <a href="#kt_btapi_runtime-libraries">libraries</a>, <a href="#kt_btapi_runtime-skip_code_gen">skip_code_gen</a>)
The Build Tools API compilation runtime: the jars the worker loads into the Build Tools API classloader, and the internal compiler plugins it passes to the compiler. Every jar is the embeddable compiler dialect (the Maven-published form of the compiler and its plugins), because the Build Tools implementation is published in that dialect only.
An artifact that is not set is inherited from base, so a runtime that replaces one artifact states only that artifact. The default runtime, //kotlin/compiler:btapi_runtime, takes every artifact from the configured Kotlin release.
ATTRIBUTES
load("@rules_kotlin//kotlin:core.bzl", "kt_compiler_plugin") kt_compiler_plugin(<a href="#kt_compiler_plugin-name">name</a>, <a href="#kt_compiler_plugin-deps">deps</a>, <a href="#kt_compiler_plugin-data">data</a>, <a href="#kt_compiler_plugin-compile_phase">compile_phase</a>, <a href="#kt_compiler_plugin-id">id</a>, <a href="#kt_compiler_plugin-options">options</a>, <a href="#kt_compiler_plugin-stubs_phase">stubs_phase</a>, <a href="#kt_compiler_plugin-target_embedded_compiler">target_embedded_compiler</a>)
Define a plugin for the Kotlin compiler to run. The plugin can then be referenced in the plugins attribute of the kt_jvm_* rules.
An example can be found under //examples/plugin:
kt_compiler_plugin( name = "open_for_testing_plugin", id = "org.jetbrains.kotlin.allopen", options = { "annotation": "plugin.OpenForTesting", }, deps = [ "//kotlin/compiler:allopen-compiler-plugin", ], ) kt_jvm_library( name = "open_for_testing", srcs = ["OpenForTesting.kt"], ) kt_jvm_library( name = "user", srcs = ["User.kt"], plugins = [":open_for_testing_plugin"], deps = [ ":open_for_testing", ], )
ATTRIBUTES
load("@rules_kotlin//kotlin:core.bzl", "kt_javac_options") kt_javac_options(<a href="#kt_javac_options-name">name</a>, <a href="#kt_javac_options-add_exports">add_exports</a>, <a href="#kt_javac_options-no_proc">no_proc</a>, <a href="#kt_javac_options-release">release</a>, <a href="#kt_javac_options-warn">warn</a>, <a href="#kt_javac_options-x_ep_disable_all_checks">x_ep_disable_all_checks</a>, <a href="#kt_javac_options-x_explicit_api_mode">x_explicit_api_mode</a>, <a href="#kt_javac_options-x_lint">x_lint</a>, <a href="#kt_javac_options-xd_suppress_notes">xd_suppress_notes</a>)
Define java compiler options for kt_jvm_* rules with java sources.
ATTRIBUTES
load("@rules_kotlin//kotlin:core.bzl", "kt_kotlinc_options") kt_kotlinc_options(<a href="#kt_kotlinc_options-name">name</a>, <a href="#kt_kotlinc_options-api_version">api_version</a>, <a href="#kt_kotlinc_options-include_stdlibs">include_stdlibs</a>, <a href="#kt_kotlinc_options-java_parameters">java_parameters</a>, <a href="#kt_kotlinc_options-jvm_default">jvm_default</a>, <a href="#kt_kotlinc_options-jvm_target">jvm_target</a>, <a href="#kt_kotlinc_options-language_version">language_version</a>, <a href="#kt_kotlinc_options-progressive">progressive</a>, <a href="#kt_kotlinc_options-warn">warn</a>, <a href="#kt_kotlinc_options-x_allow_kotlin_package">x_allow_kotlin_package</a>, <a href="#kt_kotlinc_options-x_allow_unstable_dependencies">x_allow_unstable_dependencies</a>, <a href="#kt_kotlinc_options-x_annotation_default_target">x_annotation_default_target</a>, <a href="#kt_kotlinc_options-x_assertions">x_assertions</a>, <a href="#kt_kotlinc_options-x_backend_threads">x_backend_threads</a>, <a href="#kt_kotlinc_options-x_consistent_data_class_copy_visibility">x_consistent_data_class_copy_visibility</a>, <a href="#kt_kotlinc_options-x_context_parameters">x_context_parameters</a>, <a href="#kt_kotlinc_options-x_context_receivers">x_context_receivers</a>, <a href="#kt_kotlinc_options-x_emit_jvm_type_annotations">x_emit_jvm_type_annotations</a>, <a href="#kt_kotlinc_options-x_enable_incremental_compilation">x_enable_incremental_compilation</a>, <a href="#kt_kotlinc_options-x_explicit_api_mode">x_explicit_api_mode</a>, <a href="#kt_kotlinc_options-x_inline_classes">x_inline_classes</a>, <a href="#kt_kotlinc_options-x_jdk_release">x_jdk_release</a>, <a href="#kt_kotlinc_options-x_jspecify_annotations">x_jspecify_annotations</a>, <a href="#kt_kotlinc_options-x_jsr_305">x_jsr_305</a>, <a href="#kt_kotlinc_options-x_jvm_default">x_jvm_default</a>, <a href="#kt_kotlinc_options-x_lambdas">x_lambdas</a>, <a href="#kt_kotlinc_options-x_multi_platform">x_multi_platform</a>, <a href="#kt_kotlinc_options-x_no_call_assertions">x_no_call_assertions</a>, <a href="#kt_kotlinc_options-x_no_optimize">x_no_optimize</a>, <a href="#kt_kotlinc_options-x_no_param_assertions">x_no_param_assertions</a>, <a href="#kt_kotlinc_options-x_no_receiver_assertions">x_no_receiver_assertions</a>, <a href="#kt_kotlinc_options-x_no_source_debug_extension">x_no_source_debug_extension</a>, <a href="#kt_kotlinc_options-x_nullability_annotations">x_nullability_annotations</a>, <a href="#kt_kotlinc_options-x_optin">x_optin</a>, <a href="#kt_kotlinc_options-x_render_internal_diagnostic_names">x_render_internal_diagnostic_names</a>, <a href="#kt_kotlinc_options-x_report_all_warnings">x_report_all_warnings</a>, <a href="#kt_kotlinc_options-x_report_perf">x_report_perf</a>, <a href="#kt_kotlinc_options-x_sam_conversions">x_sam_conversions</a>, <a href="#kt_kotlinc_options-x_skip_prerelease_check">x_skip_prerelease_check</a>, <a href="#kt_kotlinc_options-x_suppress_version_warnings">x_suppress_version_warnings</a>, <a href="#kt_kotlinc_options-x_suppress_warning">x_suppress_warning</a>, <a href="#kt_kotlinc_options-x_type_enhancement_improvements_strict_mode">x_type_enhancement_improvements_strict_mode</a>, <a href="#kt_kotlinc_options-x_use_fir_lt">x_use_fir_lt</a>, <a href="#kt_kotlinc_options-x_use_k2">x_use_k2</a>, <a href="#kt_kotlinc_options-x_warning_level">x_warning_level</a>, <a href="#kt_kotlinc_options-x_when_guards">x_when_guards</a>, <a href="#kt_kotlinc_options-x_xlanguage">x_xlanguage</a>)
Define kotlin compiler options.
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| api_version | Allow using declarations from only the specified version of bundled libraries. Overrides the toolchain's api_version when set. | String | optional | "" |
| include_stdlibs | Don't automatically include the Kotlin standard libraries into the classpath (stdlib and reflect). | String | optional | "all" |
| java_parameters | Generate metadata for Java 1.8+ reflection on method parameters. | Boolean | optional | False |
| jvm_default | Specifies how to generate JVM default methods for interface declarations with bodies. This is the stable replacement for x_jvm_default (-Xjvm-default). Available from Kotlin 2.2. Options: - ‘off’: Don't pass the flag (uses compiler default, which is ‘enable’ in Kotlin 2.2+). - ‘enable’: Generate default methods and DefaultImpls for compatibility. - ‘no-compatibility’: Generate default methods without DefaultImpls classes. - ‘disable’: Do not generate JVM default methods (was the default up to Kotlin 2.1). | String | optional | "off" |
| jvm_target | The target version of the generated JVM bytecode | String | optional | "" |
| language_version | Provide source compatibility with the specified version of Kotlin. Overrides the toolchain's language_version when set. | String | optional | "" |
| progressive | Enable progressive compiler mode. In this mode, deprecations and bug fixes for unstable code take effect immediately instead of going through a graceful migration cycle. | Boolean | optional | False |
| warn | Control warning behaviour. | String | optional | "report" |
| x_allow_kotlin_package | Allow compiling code in the ‘kotlin’ package, and allow not requiring ‘kotlin.stdlib’ in ‘module-info’. | Boolean | optional | False |
| x_allow_unstable_dependencies | Do not report errors on classes in dependencies that were compiled by an unstable version of the Kotlin compiler. | Boolean | optional | False |
| x_annotation_default_target | Change the default annotation targets for constructor properties: -Xannotation-default-target=first-only: use the first of the following allowed targets: ‘@param:’, ‘@property:’, ‘@field:’; -Xannotation-default-target=first-only-warn: same as first-only, and raise warnings when both ‘@param:’ and either ‘@property:’ or ‘@field:’ are allowed; -Xannotation-default-target=param-property: use ‘@param:’ target if applicable, and also use the first of either ‘@property:’ or ‘@field:’; default: ‘first-only-warn’ in language version 2.2+, ‘first-only’ in version 2.1 and before. | String | optional | "off" |
| x_assertions | Configures how assertions are handled. The ‘jvm’ option enables assertions in JVM code. | String | optional | "" |
| x_backend_threads | When using the IR backend, run lowerings by file in N parallel threads. 0 means use a thread per processor core. Default value is 1. | Integer | optional | 1 |
| x_consistent_data_class_copy_visibility | The effect of this compiler flag is the same as applying @ConsistentCopyVisibility annotation to all data classes in the module. See https://youtrack.jetbrains.com/issue/KT-11914 | Boolean | optional | False |
| x_context_parameters | Enable experimental context parameters (Kotlin 2.2+). | Boolean | optional | False |
| x_context_receivers | Enable experimental context receivers. | Boolean | optional | False |
| x_emit_jvm_type_annotations | Basic support for type annotations in JVM bytecode. | Boolean | optional | False |
| x_enable_incremental_compilation | Enable incremental compilation | Boolean | optional | False |
| x_explicit_api_mode | Enable explicit API mode for Kotlin libraries. | String | optional | "off" |
| x_inline_classes | Enable experimental inline classes | Boolean | optional | False |
| x_jdk_release | Compile against the specified JDK API version, similarly to javac's ‘-release’. This requires JDK 9 or newer. The supported versions depend on the JDK used; for JDK 25+, the supported versions are 1.8 and 9-25. This also sets the value of ‘-jvm-target’ to be equal to the selected JDK version. | String | optional | "" |
| x_jspecify_annotations | Controls how JSpecify annotations are treated. Options are ‘default’, ‘ignore’, ‘warn’, and ‘strict’. | String | optional | "" |
| x_jsr_305 | Specifies how to handle JSR-305 annotations in Kotlin code. Options are ‘default’, ‘ignore’, ‘warn’, and ‘strict’. | String | optional | "" |
| x_jvm_default | DEPRECATED: Use jvm_default instead for Kotlin 2.2+. Specifies that a JVM default method should be generated for non-abstract Kotlin interface member. Migration to jvm_default: - x_jvm_default=all -> jvm_default=no-compatibility - x_jvm_default=all-compatibility -> jvm_default=enable - x_jvm_default=disable -> jvm_default=disable | String | optional | "off" |
| x_lambdas | Change codegen behavior of lambdas. Defaults to “class” (anonymous inner classes), which differs from Kotlin 2.x/Gradle default of “indy” (invokedynamic). Set to “indy” for Gradle-compatible bytecode. | String | optional | "class" |
| x_multi_platform | Enable experimental language support for multi-platform projects | Boolean | optional | False |
| x_no_call_assertions | Don't generate not-null assertions for arguments of platform types | Boolean | optional | False |
| x_no_optimize | Disable optimizations | Boolean | optional | False |
| x_no_param_assertions | Don't generate not-null assertions on parameters of methods accessible from Java | Boolean | optional | False |
| x_no_receiver_assertions | Don't generate not-null assertion for extension receiver arguments of platform types | Boolean | optional | False |
| x_no_source_debug_extension | Do not generate @kotlin.jvm.internal.SourceDebugExtension annotation on a class with the copy of SMAP | Boolean | optional | False |
| x_nullability_annotations | Configure how Kotlin treats nullability annotations on Java types, per annotation class. Map the fully-qualified annotation class name (prefixed with ‘@’) to a mode: ‘ignore’, ‘warn’, or ‘strict’. Ex: {‘@jakarta.annotation.Nullable’: ‘strict’, ‘@jakarta.annotation.Nonnull’: ‘strict’}. Use x_jsr305 for javax.annotation (JSR-305) and x_jspecify_annotations for org.jspecify. | Dictionary: String -> String | optional | {} |
| x_optin | Define APIs to opt-in to. | List of strings | optional | [] |
| x_render_internal_diagnostic_names | Render the internal names of warnings and errors. | Boolean | optional | False |
| x_report_all_warnings | Report all warnings even if errors are found. | Boolean | optional | False |
| x_report_perf | Report detailed performance statistics | Boolean | optional | False |
| x_sam_conversions | Change codegen behavior of SAM/functional interfaces. Defaults to “indy” (invokedynamic via LambdaMetafactory), matching Kotlin compiler's own default since 1.5. Set to “class” for legacy anonymous-class codegen. | String | optional | "indy" |
| x_skip_prerelease_check | Suppress errors thrown when using pre-release classes. | Boolean | optional | False |
| x_suppress_version_warnings | Suppress warnings about outdated, inconsistent, or experimental language or API versions. | Boolean | optional | False |
| x_suppress_warning | Suppress specific warnings globally | List of strings | optional | [] |
| x_type_enhancement_improvements_strict_mode | Enables strict mode for type enhancement improvements, enforcing stricter type checking and enhancements. | Boolean | optional | False |
| x_use_fir_lt | Compile using LightTree parser with Front-end IR. Warning: this feature is far from being production-ready | Boolean | optional | False |
| x_use_k2 | Compile using experimental K2. K2 is a new compiler pipeline, no compatibility guarantees are yet provided | Boolean | optional | False |
| x_warning_level | Suppress specific warnings globally. Ex: ‘OPTION’: ‘(error|warning|disabled)’ | Dictionary: String -> String | optional | {} |
| x_when_guards | Enable experimental language support for when guards. | Boolean | optional | False |
| x_xlanguage | Enable or disable the specified language feature. Not intended for production use; prefer language_version or the dedicated feature flags. | List of strings | optional | [] |
load("@rules_kotlin//kotlin:core.bzl", "kt_ksp_plugin") kt_ksp_plugin(<a href="#kt_ksp_plugin-name">name</a>, <a href="#kt_ksp_plugin-deps">deps</a>, <a href="#kt_ksp_plugin-generates_java">generates_java</a>, <a href="#kt_ksp_plugin-options">options</a>, <a href="#kt_ksp_plugin-processor_class">processor_class</a>, <a href="#kt_ksp_plugin-target_embedded_compiler">target_embedded_compiler</a>)
Define a KSP plugin for the Kotlin compiler to run. The plugin can then be referenced in the plugins attribute of the kt_jvm_* and kt_android_* rules.
An example can be found under //examples/ksp:
kt_ksp_plugin( name = "moshi-kotlin-codegen", processor_class = "com.squareup.moshi.kotlin.codegen.ksp.JsonClassSymbolProcessorProvider", deps = [ "@maven//:com_squareup_moshi_moshi", "@maven//:com_squareup_moshi_moshi_kotlin", "@maven//:com_squareup_moshi_moshi_kotlin_codegen", ], ) kt_jvm_library( name = "lib", srcs = glob(["*.kt"]), plugins = ["//:moshi-kotlin-codegen"], )
ATTRIBUTES
load("@rules_kotlin//kotlin:core.bzl", "kt_plugin_cfg") kt_plugin_cfg(<a href="#kt_plugin_cfg-name">name</a>, <a href="#kt_plugin_cfg-deps">deps</a>, <a href="#kt_plugin_cfg-data">data</a>, <a href="#kt_plugin_cfg-options">options</a>, <a href="#kt_plugin_cfg-plugin">plugin</a>)
Configurations for kt_compiler_plugin, ksp_plugin, and java_plugin.
This allows setting options and dependencies independently from the initial plugin definition.
ATTRIBUTES
load("@rules_kotlin//kotlin:core.bzl", "BtapiRuntimeInfo") BtapiRuntimeInfo(<a href="#BtapiRuntimeInfo-build_tools_impl">build_tools_impl</a>, <a href="#BtapiRuntimeInfo-compiler">compiler</a>, <a href="#BtapiRuntimeInfo-jdeps_gen">jdeps_gen</a>, <a href="#BtapiRuntimeInfo-jvm_abi_gen">jvm_abi_gen</a>, <a href="#BtapiRuntimeInfo-kapt">kapt</a>, <a href="#BtapiRuntimeInfo-libraries">libraries</a>, <a href="#BtapiRuntimeInfo-skip_code_gen">skip_code_gen</a>)
The complete Build Tools API compilation runtime: the classloader group and the internal compiler plugins. Every jar is the embeddable compiler dialect.
FIELDS
load("@rules_kotlin//kotlin:core.bzl", "define_kt_toolchain") define_kt_toolchain(<a href="#define_kt_toolchain-name">name</a>, <a href="#define_kt_toolchain-language_version">language_version</a>, <a href="#define_kt_toolchain-api_version">api_version</a>, <a href="#define_kt_toolchain-jvm_target">jvm_target</a>, <a href="#define_kt_toolchain-experimental_use_abi_jars">experimental_use_abi_jars</a>, <a href="#define_kt_toolchain-experimental_treat_internal_as_private_in_abi_jars">experimental_treat_internal_as_private_in_abi_jars</a>, <a href="#define_kt_toolchain-experimental_remove_private_classes_in_abi_jars">experimental_remove_private_classes_in_abi_jars</a>, <a href="#define_kt_toolchain-experimental_remove_debug_info_in_abi_jars">experimental_remove_debug_info_in_abi_jars</a>, <a href="#define_kt_toolchain-experimental_preserve_declaration_order">experimental_preserve_declaration_order</a>, <a href="#define_kt_toolchain-experimental_remove_data_class_copy_if_constructor_is_private">experimental_remove_data_class_copy_if_constructor_is_private</a>, <a href="#define_kt_toolchain-experimental_strict_kotlin_deps">experimental_strict_kotlin_deps</a>, <a href="#define_kt_toolchain-experimental_report_unused_deps">experimental_report_unused_deps</a>, <a href="#define_kt_toolchain-experimental_reduce_classpath_mode">experimental_reduce_classpath_mode</a>, <a href="#define_kt_toolchain-experimental_multiplex_workers">experimental_multiplex_workers</a>, <a href="#define_kt_toolchain-experimental_multiplex_sandboxing">experimental_multiplex_sandboxing</a>, <a href="#define_kt_toolchain-supports_path_mapping">supports_path_mapping</a>, <a href="#define_kt_toolchain-experimental_build_tools_api">experimental_build_tools_api</a>, <a href="#define_kt_toolchain-btapi_runtime">btapi_runtime</a>, <a href="#define_kt_toolchain-javac_options">javac_options</a>, <a href="#define_kt_toolchain-kotlinc_options">kotlinc_options</a>, <a href="#define_kt_toolchain-jvm_stdlibs">jvm_stdlibs</a>, <a href="#define_kt_toolchain-jvm_runtime">jvm_runtime</a>, <a href="#define_kt_toolchain-jacocorunner">jacocorunner</a>, <a href="#define_kt_toolchain-exec_compatible_with">exec_compatible_with</a>, <a href="#define_kt_toolchain-target_compatible_with">target_compatible_with</a>, <a href="#define_kt_toolchain-target_settings">target_settings</a>)
Define the Kotlin toolchain.
The legacy invocation runs the compiler of the bundled CLI distribution. When the Build Tools API compilation is enabled, through experimental_build_tools_api, through btapi_runtime, or through the build setting //kotlin/settings:experimental_build_tools_api, the toolchain runs a Build Tools API runtime: the Build Tools implementation, the embeddable compiler, the libraries they need, and the internal compiler plugins in the embeddable dialect.
PARAMETERS
load("@rules_kotlin//kotlin:core.bzl", "kt_register_toolchains") kt_register_toolchains()
This macro registers the kotlin toolchain.
Stubs for stardoc generation.
load("@rules_kotlin//kotlin:repositories.doc.bzl", "kotlin_repositories") kotlin_repositories(<a href="#kotlin_repositories-is_bzlmod">is_bzlmod</a>, <a href="#kotlin_repositories-compiler_repository_name">compiler_repository_name</a>, <a href="#kotlin_repositories-ksp_repository_name">ksp_repository_name</a>, <a href="#kotlin_repositories-compiler_release">compiler_release</a>, <a href="#kotlin_repositories-ksp_compiler_release">ksp_compiler_release</a>, <a href="#kotlin_repositories-btapi_impl_releases">btapi_impl_releases</a>)
Call this in the WORKSPACE file to setup the Kotlin rules.
PARAMETERS
load("@rules_kotlin//kotlin:repositories.doc.bzl", "versions") versions.use_repository(<a href="#versions.use_repository-rule">rule</a>, <a href="#versions.use_repository-name">name</a>, <a href="#versions.use_repository-version">version</a>, <a href="#versions.use_repository-kwargs">**kwargs</a>)
PARAMETERS
| Name | Description | Default Value |
|---|---|---|
| rule | - | none |
| name | - | none |
| version | - | none |
| kwargs | - | none |