Skip to content

Commit b2ee796

Browse files
authored
[maintenance] Add Kotlin 2.3 compiler options definitions (#1445)
Closes #1444
1 parent b412275 commit b2ee796

File tree

4 files changed

+912
-4
lines changed

4 files changed

+912
-4
lines changed

docs/kotlin.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ Define java compiler options for `kt_jvm_*` rules with java sources.
385385
<pre>
386386
load("@rules_kotlin//kotlin:core.bzl", "kt_kotlinc_options")
387387

388-
kt_kotlinc_options(<a href="#kt_kotlinc_options-name">name</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_target">jvm_target</a>, <a href="#kt_kotlinc_options-warn">warn</a>,
388+
kt_kotlinc_options(<a href="#kt_kotlinc_options-name">name</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-warn">warn</a>,
389389
<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>,
390390
<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>,
391391
<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>,
@@ -408,6 +408,7 @@ Define kotlin compiler options.
408408
| <a id="kt_kotlinc_options-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | |
409409
| <a id="kt_kotlinc_options-include_stdlibs"></a>include_stdlibs | Don't automatically include the Kotlin standard libraries into the classpath (stdlib and reflect). | String | optional | `"all"` |
410410
| <a id="kt_kotlinc_options-java_parameters"></a>java_parameters | Generate metadata for Java 1.8+ reflection on method parameters. | Boolean | optional | `False` |
411+
| <a id="kt_kotlinc_options-jvm_default"></a>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"` |
411412
| <a id="kt_kotlinc_options-jvm_target"></a>jvm_target | The target version of the generated JVM bytecode | String | optional | `""` |
412413
| <a id="kt_kotlinc_options-warn"></a>warn | Control warning behaviour. | String | optional | `"report"` |
413414
| <a id="kt_kotlinc_options-x_annotation_default_target"></a>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"` |
@@ -423,7 +424,7 @@ Define kotlin compiler options.
423424
| <a id="kt_kotlinc_options-x_jdk_release"></a>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 17+, the supported versions are 1.8 and 9-21. This also sets the value of '-jvm-target' to be equal to the selected JDK version. | String | optional | `""` |
424425
| <a id="kt_kotlinc_options-x_jspecify_annotations"></a>x_jspecify_annotations | Controls how JSpecify annotations are treated. Options are 'default', 'ignore', 'warn', and 'strict'. | String | optional | `""` |
425426
| <a id="kt_kotlinc_options-x_jsr_305"></a>x_jsr_305 | Specifies how to handle JSR-305 annotations in Kotlin code. Options are 'default', 'ignore', 'warn', and 'strict'. | String | optional | `""` |
426-
| <a id="kt_kotlinc_options-x_jvm_default"></a>x_jvm_default | Specifies that a JVM default method should be generated for non-abstract Kotlin interface member. | String | optional | `"off"` |
427+
| <a id="kt_kotlinc_options-x_jvm_default"></a>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"` |
427428
| <a id="kt_kotlinc_options-x_lambdas"></a>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"` |
428429
| <a id="kt_kotlinc_options-x_multi_platform"></a>x_multi_platform | Enable experimental language support for multi-platform projects | Boolean | optional | `False` |
429430
| <a id="kt_kotlinc_options-x_no_call_assertions"></a>x_no_call_assertions | Don't generate not-null assertions for arguments of platform types | Boolean | optional | `False` |

src/main/starlark/core/options/opts.kotlinc.bzl

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,27 @@ _KOPTS_ALL = {
7575
True: ["-java-parameters"],
7676
},
7777
),
78+
"jvm_default": struct(
79+
flag = "-jvm-default",
80+
args = dict(
81+
default = "off",
82+
doc = """Specifies how to generate JVM default methods for interface declarations with bodies.
83+
This is the stable replacement for x_jvm_default (-Xjvm-default). Available from Kotlin 2.2.
84+
Options:
85+
- 'off': Don't pass the flag (uses compiler default, which is 'enable' in Kotlin 2.2+).
86+
- 'enable': Generate default methods and DefaultImpls for compatibility.
87+
- 'no-compatibility': Generate default methods without DefaultImpls classes.
88+
- 'disable': Do not generate JVM default methods (was the default up to Kotlin 2.1).""",
89+
values = ["off", "enable", "no-compatibility", "disable"],
90+
),
91+
type = attr.string,
92+
value_to_flag = {
93+
"disable": ["-jvm-default=disable"],
94+
"enable": ["-jvm-default=enable"],
95+
"no-compatibility": ["-jvm-default=no-compatibility"],
96+
"off": None,
97+
},
98+
),
7899
"jvm_target": struct(
79100
args = dict(
80101
default = "",
@@ -275,7 +296,12 @@ default: 'first-only-warn' in language version 2.2+, 'first-only' in version 2.1
275296
flag = "-Xjvm-default",
276297
args = dict(
277298
default = "off",
278-
doc = "Specifies that a JVM default method should be generated for non-abstract Kotlin interface member.",
299+
doc = """DEPRECATED: Use jvm_default instead for Kotlin 2.2+.
300+
Specifies that a JVM default method should be generated for non-abstract Kotlin interface member.
301+
Migration to jvm_default:
302+
- x_jvm_default=all -> jvm_default=no-compatibility
303+
- x_jvm_default=all-compatibility -> jvm_default=enable
304+
- x_jvm_default=disable -> jvm_default=disable""",
279305
values = ["off", "enable", "disable", "compatibility", "all-compatibility", "all"],
280306
),
281307
type = attr.string,

0 commit comments

Comments
 (0)