kt_js_import
kt_js_import(name, kwargs)
PARAMETERS
Name | Description | Default Value |
---|---|---|
name | - |
none |
kwargs | - |
none |
kt_js_library
kt_js_library(name, kwargs)
PARAMETERS
Name | Description | Default Value |
---|---|---|
name | - |
none |
kwargs | - |
none |
kt_javac_options
kt_javac_options(name, warn, x_ep_disable_all_checks, x_lint, xd_suppress_notes)
Define java compiler options for `kt_jvm_*` rules with java sources.
ATTRIBUTES
Name | Description | Type | Mandatory | Default |
---|---|---|---|---|
name | A unique name for this target. | Name | required | |
warn | Control warning behaviour. | String | optional | "report" |
x_ep_disable_all_checks | See javac -XepDisableAllChecks documentation | Boolean | optional | False |
x_lint | See javac -Xlint: documentation | List of strings | optional | [] |
xd_suppress_notes | See javac -XDsuppressNotes documentation | Boolean | optional | False |
kt_jvm_binary
kt_jvm_binary(name, associates, data, deps, friends, 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
Name | Description | Type | Mandatory | Default |
---|---|---|---|---|
name | A unique name for this target. | Name | required | |
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 | [] |
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 | [] |
deps | A list of dependencies of this rule.See general comments about deps at Attributes common to all build rules. |
List of labels | optional | [] |
friends | A single Kotlin dep which allows Kotlin code in other modules access to internal members. Currently uses the output jar of the module -- i.e., exported deps won't be included. [DEPRECATED, use "associates" instead] | List of labels | optional | [] |
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, files residing under common prefix such as src/main/resources or src/test/resources or kotlin will have stripping applied by convention. |
String | optional | "" |
resources | A list of files that should be include in a Java jar. | List of labels | optional | [] |
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 | [] |
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 | [] |
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
Name | Description | Type | Mandatory | Default |
---|---|---|---|---|
name | A unique name for this target. | Name | required | |
deps | Compile and runtime dependencies | 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. Unlike 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 | [] |
jar | The jar listed here is equivalent to an export attribute. | Label | optional | None |
jars | The 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 labels | optional | [] |
neverlink | If true only use this library for compilation and not at runtime. | Boolean | optional | False |
runtime_deps | Additional runtime deps. | List of labels | optional | [] |
srcjar | The sources for the class jar. | Label | optional | //third_party:empty.jar |
kt_jvm_library
kt_jvm_library(name, associates, data, deps, exported_compiler_plugins, exports, friends, 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
Name | Description | Type | Mandatory | Default |
---|---|---|---|---|
name | A unique name for this target. | Name | required | |
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 | [] |
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 | [] |
deps | A list of dependencies of this rule.See general comments about deps at Attributes common to all build rules. |
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. Unlike java_plugin s 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 | [] |
friends | A single Kotlin dep which allows Kotlin code in other modules access to internal members. Currently uses the output jar of the module -- i.e., exported deps won't be included. [DEPRECATED, use "associates" instead] | List of labels | optional | [] |
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, files residing under common prefix such as src/main/resources or src/test/resources or kotlin will have stripping applied by convention. |
String | optional | "" |
resources | A list of files that should be include in a Java jar. | List of labels | optional | [] |
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 | [] |
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 | [] |
kt_jvm_test
kt_jvm_test(name, associates, data, deps, friends, 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
Name | Description | Type | Mandatory | Default |
---|---|---|---|---|
name | A unique name for this target. | Name | required | |
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 | [] |
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 | [] |
deps | A list of dependencies of this rule.See general comments about deps at Attributes common to all build rules. |
List of labels | optional | [] |
friends | A single Kotlin dep which allows Kotlin code in other modules access to internal members. Currently uses the output jar of the module -- i.e., exported deps won't be included. [DEPRECATED, use "associates" instead] | List of labels | optional | [] |
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, files residing under common prefix such as src/main/resources or src/test/resources or kotlin will have stripping applied by convention. |
String | optional | "" |
resources | A list of files that should be include in a Java jar. | List of labels | optional | [] |
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 | [] |
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 | [] |
test_class | The Java class to be loaded by the test runner. | String | optional | "" |
ktlint_config
ktlint_config(name, editorconfig)
Used to configure ktlint.
`ktlint` can be configured to use a `.editorconfig`, as documented at
https://github.com/pinterest/ktlint/#editorconfig
ATTRIBUTES
Name | Description | Type | Mandatory | Default |
---|---|---|---|---|
name | A unique name for this target. | Name | required | |
editorconfig | Editor config file to use | Label | optional | None |
ktlint_fix
ktlint_fix(name, config, srcs)
Lint Kotlin files and automatically fix them as needed
ATTRIBUTES
Name | Description | Type | Mandatory | Default |
---|---|---|---|---|
name | A unique name for this target. | Name | required | |
config | ktlint_config to use | Label | optional | None |
srcs | Source files to review and fix | List of labels | required |
ktlint_test
ktlint_test(name, config, srcs)
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 | |
config | ktlint_config to use | Label | optional | None |
srcs | Source files to lint | List of labels | required |
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
Name | Description | Type | Mandatory | Default |
---|---|---|---|---|
name | A unique name for this target. | Name | required | |
compile_phase | Runs the compiler plugin during kotlin compilation. Known examples: allopen , sam_with_reciever |
Boolean | optional | True |
deps | The list of libraries to be added to the compiler's plugin classpath | List of labels | optional | [] |
id | The ID of the plugin | String | required | |
options | Dictionary 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 -> String | optional | {} |
stubs_phase | Runs the compiler plugin in kapt stub generation. | Boolean | optional | True |
target_embedded_compiler | Plugin was compiled against the embeddable kotlin compiler. These plugins expect shaded kotlinc dependencies, and will fail when running against a non-embeddable compiler. | Boolean | optional | False |
kt_javac_options
kt_javac_options(name, warn, x_ep_disable_all_checks, x_lint, xd_suppress_notes)
Define java compiler options for `kt_jvm_*` rules with java sources.
ATTRIBUTES
Name | Description | Type | Mandatory | Default |
---|---|---|---|---|
name | A unique name for this target. | Name | required | |
warn | Control warning behaviour. | String | optional | "report" |
x_ep_disable_all_checks | See javac -XepDisableAllChecks documentation | Boolean | optional | False |
x_lint | See javac -Xlint: documentation | List of strings | optional | [] |
xd_suppress_notes | See javac -XDsuppressNotes documentation | Boolean | optional | False |
kt_kotlinc_options
kt_kotlinc_options(name, include_stdlibs, java_parameters, warn, x_allow_jvm_ir_dependencies, x_allow_result_return_type, x_inline_classes, x_jvm_default, x_multi_platform, x_no_optimized_callable_references, x_skip_prerelease_check, x_use_experimental, x_use_ir)
Define kotlin compiler options.
ATTRIBUTES
Name | Description | Type | Mandatory | Default |
---|---|---|---|---|
name | A unique name for this target. | Name | required | |
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 |
warn | Control warning behaviour. | String | optional | "report" |
x_allow_jvm_ir_dependencies | Suppress errors thrown when using dependencies not compiled by the IR backend. Only available in 1.4. | Boolean | optional | False |
x_allow_result_return_type | Enable kotlin.Result as a return type | Boolean | optional | False |
x_inline_classes | Enable experimental inline classes | Boolean | optional | False |
x_jvm_default | Specifies that a JVM default method should be generated for non-abstract Kotlin interface member. | String | optional | "off" |
x_multi_platform | Enable experimental language support for multi-platform projects | Boolean | optional | False |
x_no_optimized_callable_references | Do not use optimized callable reference superclasses. Available from 1.4. | Boolean | optional | False |
x_skip_prerelease_check | Suppress errors thrown when using pre-release classes. | Boolean | optional | False |
x_use_experimental | Allow the experimental language features. | Boolean | optional | True |
x_use_ir | Enable or disable the experimental IR backend. | Boolean | optional | False |
x_explicit_api_mode | Enable or disable Kotlin explicit API mode for library developers. | String | optional | "off" |
define_kt_toolchain
define_kt_toolchain(name, language_version, api_version, jvm_target, experimental_use_abi_jars, experimental_strict_kotlin_deps, experimental_report_unused_deps, experimental_reduce_classpath_mode, experimental_multiplex_workers, javac_options, kotlinc_options, jacocorunner)
Define the Kotlin toolchain.
PARAMETERS
Name | Description | Default 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
kt_register_toolchains()
This macro registers the kotlin toolchain.
PARAMETERS
kotlin_repositories
kotlin_repositories(compiler_repository_name, compiler_release, configured_repository_name)
Call this in the WORKSPACE file to setup the Kotlin rules.
PARAMETERS
Name | Description | Default Value |
---|---|---|
compiler_repository_name | - |
"com_github_jetbrains_kotlin" |
compiler_release | (internal) version provider from versions.bzl. | struct() |
configured_repository_name | - |
"io_bazel_rules_kotlin_configured" |