kt_js_import

PARAMETERS

NameDescriptionDefault Value
name - none
kwargs - none

kt_js_library

PARAMETERS

NameDescriptionDefault Value
name - none
kwargs - none

kt_javac_options

kt_javac_options(name, warn, x_ep_disable_all_checks, x_explicit_api_mode, x_lint, xd_suppress_notes)

Define java compiler options for `kt_jvm_*` rules with java sources.

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
warnControl warning behaviour.Stringoptional“report”
x_ep_disable_all_checksSee javac -XepDisableAllChecks documentationBooleanoptionalFalse
x_explicit_api_modeEnable explicit API mode for Kotlin libraries.Stringoptional“off”
x_lintSee javac -Xlint: documentationList of stringsoptional[]
xd_suppress_notesSee javac -XDsuppressNotes documentationBooleanoptionalFalse

kt_jvm_binary

kt_jvm_binary(name, associates, data, deps, javac_opts, jvm_flags, kotlinc_opts, main_class, module_name, plugins, resource_jars, resource_strip_prefix, resources, runtime_deps, srcs)

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`](https://docs.bazel.build/versions/master/be/java.html#java_binary).
    It is appropriate for building workspace utilities. `java_binary` should be preferred for release artefacts.

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
associatesKotlin 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 labelsoptional[]
dataThe list of files needed by this rule at runtime. See general comments about data at Attributes common to all build rules.List of labelsoptional[]
depsA list of dependencies of this rule.See general comments about deps at Attributes common to all build rules.List of labelsoptional[]
javac_optsJavac options to be used when compiling this target. These opts if provided will be used instead of the ones provided to the toolchain.LabeloptionalNone
jvm_flagsA list of flags to embed in the wrapper script generated for running this binary. Note: does not yet support make variable substitution.List of stringsoptional[]
kotlinc_optsKotlinc options to be used when compiling this target. These opts if provided will be used instead of the ones provided to the toolchain.LabeloptionalNone
main_className of class with main() method to use as entry point.Stringrequired
module_nameThe 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.Stringoptional""
plugins-List of labelsoptional[]
resource_jarsSet of archives containing Java resources. If specified, the contents of these jars are merged into the output jar.List of labelsoptional[]
resource_strip_prefixThe path prefix to strip from Java resources, files residing under common prefix such as src/main/resources or src/test/resources or kotlin will have stripping applied by convention.Stringoptional""
resourcesA list of files that should be include in a Java jar.List of labelsoptional[]
runtime_depsLibraries 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 labelsoptional[]
srcsThe 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 labelsoptional[]

kt_jvm_import

kt_jvm_import(name, deps, exported_compiler_plugins, exports, jar, jars, neverlink, runtime_deps, srcjar)

Import Kotlin jars.
    
    ## examples
    
    ```bzl
    # 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

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
depsCompile and runtime dependenciesList of labelsoptional[]
exported_compiler_pluginsExported 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. Unlike java_plugins' exported_plugins, this is not transitive
List of labelsoptional[]
exportsExported 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 labelsoptional[]
jarThe jar listed here is equivalent to an export attribute.LabeloptionalNone
jarsThe jars listed here are equavalent to an export attribute. The label should be either to a single class jar, or one or more filegroup labels. The filegroups, when resolved, must contain only one jar containing classes, and (optionally) one peer file containing sources, named <jarname>-sources.jar.

DEPRECATED - please use jar and srcjar attributes.
List of labelsoptional[]
neverlinkIf true only use this library for compilation and not at runtime.BooleanoptionalFalse
runtime_depsAdditional runtime deps.List of labelsoptional[]
srcjarThe sources for the class jar.Labeloptional//third_party:empty.jar

kt_jvm_library

kt_jvm_library(name, associates, data, deps, exported_compiler_plugins, exports, javac_opts, kotlinc_opts, module_name, neverlink, plugins, resource_jars, resource_strip_prefix, resources, runtime_deps, srcs)

This rule compiles and links Kotlin and Java sources into a .jar file.

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
associatesKotlin 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 labelsoptional[]
dataThe list of files needed by this rule at runtime. See general comments about data at Attributes common to all build rules.List of labelsoptional[]
depsA list of dependencies of this rule.See general comments about deps at Attributes common to all build rules.List of labelsoptional[]
exported_compiler_pluginsExported 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. Unlike java_plugins exported_plugins, this is not transitive
List of labelsoptional[]
exportsExported 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 labelsoptional[]
javac_optsJavac options to be used when compiling this target. These opts if provided will be used instead of the ones provided to the toolchain.LabeloptionalNone
kotlinc_optsKotlinc options to be used when compiling this target. These opts if provided will be used instead of the ones provided to the toolchain.LabeloptionalNone
module_nameThe 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.Stringoptional""
neverlinkIf true only use this library for compilation and not at runtime.BooleanoptionalFalse
plugins-List of labelsoptional[]
resource_jarsSet of archives containing Java resources. If specified, the contents of these jars are merged into the output jar.List of labelsoptional[]
resource_strip_prefixThe path prefix to strip from Java resources, files residing under common prefix such as src/main/resources or src/test/resources or kotlin will have stripping applied by convention.Stringoptional""
resourcesA list of files that should be include in a Java jar.List of labelsoptional[]
runtime_depsLibraries 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 labelsoptional[]
srcsThe 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 labelsoptional[]

kt_jvm_test

kt_jvm_test(name, associates, data, deps, env, javac_opts, jvm_flags, kotlinc_opts, main_class, module_name, plugins, resource_jars, resource_strip_prefix, resources, runtime_deps, srcs, test_class)

Setup a simple kotlin_test.
    
    **Notes:**
    * The kotlin test library is not added implicitly, it is available with the label
    `@com_github_jetbrains_kotlin//:kotlin-test`.

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
associatesKotlin 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 labelsoptional[]
dataThe list of files needed by this rule at runtime. See general comments about data at Attributes common to all build rules.List of labelsoptional[]
depsA list of dependencies of this rule.See general comments about deps at Attributes common to all build rules.List of labelsoptional[]
envSpecifies additional environment variables to set when the target is executed by bazel test.Dictionary: String -> Stringoptional{}
javac_optsJavac options to be used when compiling this target. These opts if provided will be used instead of the ones provided to the toolchain.LabeloptionalNone
jvm_flagsA list of flags to embed in the wrapper script generated for running this binary. Note: does not yet support make variable substitution.List of stringsoptional[]
kotlinc_optsKotlinc options to be used when compiling this target. These opts if provided will be used instead of the ones provided to the toolchain.LabeloptionalNone
main_class-Stringoptional“com.google.testing.junit.runner.BazelTestRunner”
module_nameThe 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.Stringoptional""
plugins-List of labelsoptional[]
resource_jarsSet of archives containing Java resources. If specified, the contents of these jars are merged into the output jar.List of labelsoptional[]
resource_strip_prefixThe path prefix to strip from Java resources, files residing under common prefix such as src/main/resources or src/test/resources or kotlin will have stripping applied by convention.Stringoptional""
resourcesA list of files that should be include in a Java jar.List of labelsoptional[]
runtime_depsLibraries 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 labelsoptional[]
srcsThe 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 labelsoptional[]
test_classThe Java class to be loaded by the test runner.Stringoptional""

ktlint_config

ktlint_config(name, android_rules_enabled, editorconfig, experimental_rules_enabled)

        Used to configure ktlint.
            
    `ktlint` can be configured to use a `.editorconfig`, as documented at
    https://github.com/pinterest/ktlint/#editorconfig

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
android_rules_enabledTurn on Android Kotlin Style Guide compatibilityBooleanoptionalFalse
editorconfigEditor config file to useLabeloptionalNone
experimental_rules_enabledTurn on experimental rules (ktlint-ruleset-experimental)BooleanoptionalFalse

ktlint_fix

ktlint_fix(name, config, srcs)

Lint Kotlin files and automatically fix them as needed

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
configktlint_config to useLabeloptionalNone
srcsSource files to review and fixList of labelsrequired

ktlint_test

ktlint_test(name, config, srcs)

Lint Kotlin files, and fail if the linter raises errors.

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
configktlint_config to useLabeloptionalNone
srcsSource files to lintList of labelsrequired

kt_compiler_plugin

kt_compiler_plugin(name, compile_phase, deps, id, options, stubs_phase, target_embedded_compiler)

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`:
    
    ```bzl
    kt_compiler_plugin(
        name = "open_for_testing_plugin",
        id = "org.jetbrains.kotlin.allopen",
        options = {
            "annotation": "plugin.OpenForTesting",
        },
        deps = [
            "@com_github_jetbrains_kotlin//: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

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
compile_phaseRuns the compiler plugin during kotlin compilation. Known examples: allopen, sam_with_recieverBooleanoptionalTrue
depsThe list of libraries to be added to the compiler's plugin classpathList of labelsoptional[]
idThe ID of the pluginStringrequired
optionsDictionary of options to be passed to the plugin. Supports the following template values:

- {generatedClasses}: directory for generated class output - {temp}: temporary directory, discarded between invocations - {generatedSources}: directory for generated source output
Dictionary: String -> Stringoptional{}
stubs_phaseRuns the compiler plugin in kapt stub generation.BooleanoptionalTrue
target_embedded_compilerPlugin was compiled against the embeddable kotlin compiler. These plugins expect shaded kotlinc dependencies, and will fail when running against a non-embeddable compiler.BooleanoptionalFalse

kt_javac_options

kt_javac_options(name, warn, x_ep_disable_all_checks, x_explicit_api_mode, x_lint, xd_suppress_notes)

Define java compiler options for `kt_jvm_*` rules with java sources.

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
warnControl warning behaviour.Stringoptional“report”
x_ep_disable_all_checksSee javac -XepDisableAllChecks documentationBooleanoptionalFalse
x_explicit_api_modeEnable explicit API mode for Kotlin libraries.Stringoptional“off”
x_lintSee javac -Xlint: documentationList of stringsoptional[]
xd_suppress_notesSee javac -XDsuppressNotes documentationBooleanoptionalFalse

kt_kotlinc_options

kt_kotlinc_options(name, include_stdlibs, java_parameters, warn, x_allow_result_return_type, x_backend_threads, x_emit_jvm_type_annotations, x_explicit_api_mode, x_inline_classes, x_jvm_default, x_lambdas, x_multi_platform, x_no_call_assertions, x_no_optimize, x_no_optimized_callable_references, x_no_param_assertions, x_no_receiver_assertions, x_optin, x_report_perf, x_sam_conversions, x_skip_prerelease_check, x_use_k2)

Define kotlin compiler options.

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
include_stdlibsDon't automatically include the Kotlin standard libraries into the classpath (stdlib and reflect).Stringoptional“all”
java_parametersGenerate metadata for Java 1.8+ reflection on method parameters.BooleanoptionalFalse
warnControl warning behaviour.Stringoptional“report”
x_allow_result_return_typeEnable kotlin.Result as a return typeBooleanoptionalFalse
x_backend_threadsWhen using the IR backend, run lowerings by file in N parallel threads. 0 means use a thread per processor core. Default value is 1.Integeroptional1
x_emit_jvm_type_annotationsBasic support for type annotations in JVM bytecode.BooleanoptionalFalse
x_explicit_api_modeEnable explicit API mode for Kotlin libraries.Stringoptional“off”
x_inline_classesEnable experimental inline classesBooleanoptionalFalse
x_jvm_defaultSpecifies that a JVM default method should be generated for non-abstract Kotlin interface member.Stringoptional“off”
x_lambdasChange codegen behavior of lambdasStringoptional“class”
x_multi_platformEnable experimental language support for multi-platform projectsBooleanoptionalFalse
x_no_call_assertionsDon't generate not-null assertions for arguments of platform typesBooleanoptionalFalse
x_no_optimizeDisable optimizationsBooleanoptionalFalse
x_no_optimized_callable_referencesDo not use optimized callable reference superclasses. Available from 1.4.BooleanoptionalFalse
x_no_param_assertionsDon't generate not-null assertions on parameters of methods accessible from JavaBooleanoptionalFalse
x_no_receiver_assertionsDon't generate not-null assertion for extension receiver arguments of platform typesBooleanoptionalFalse
x_optinDefine APIs to opt-in to.List of stringsoptional[]
x_report_perfReport detailed performance statisticsBooleanoptionalFalse
x_sam_conversionsChange codegen behavior of SAM/functional interfacesStringoptional“class”
x_skip_prerelease_checkSuppress errors thrown when using pre-release classes.BooleanoptionalFalse
x_use_k2Compile using experimental K2. K2 is a new compiler pipeline, no compatibility guarantees are yet providedBooleanoptionalFalse

define_kt_toolchain

Define the Kotlin toolchain.

PARAMETERS

NameDescriptionDefault Value
name - none
language_version - None
api_version - None
jvm_target - None
experimental_use_abi_jars - False
experimental_strict_kotlin_deps - None
experimental_report_unused_deps - None
experimental_reduce_classpath_mode - None
experimental_multiplex_workers - None
javac_options - Label(“//kotlin/internal:default_javac_options”)
kotlinc_options - Label(“//kotlin/internal:default_kotlinc_options”)
jacocorunner - None

kt_register_toolchains

This macro registers the kotlin toolchain.

kotlin_repositories

Call this in the WORKSPACE file to setup the Kotlin rules.

PARAMETERS

NameDescriptionDefault Value
compiler_repository_namefor the kotlinc compiler repository.“com_github_jetbrains_kotlin”
compiler_releaseversion provider from versions.bzl.struct()
configured_repository_namefor the default versioned kt_* rules repository. If None, no versioned repository is created.“io_bazel_rules_kotlin_configured”