全部配置 / KN-XANNOTATION-DEFAULT-TARGET
Xannotation-default-target
Xannotation-default-target · KN-XANNOTATION-DEFAULT-TARGET · 编译器参数(Native)
默认值:未设置。未指定则为空。使用场合:场景可配。场景可配:有明确目标(性能、包体、安全、兼容)时再改。
它是做什么的
用途。更改构造属性的默认注解目标。原文: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:' …
影响。实验/高级编译开关;默认保持关闭,改前需可复现、可回滚。
适用场景。场景可配。有明确需求再改,无需求时保持发行版默认更稳妥。改前核对目标限制与联动项,改后做冒烟。
取值说明
可写。first-only|first-only-warn|param-property (字符串参数。valueDescription=first-only|first-only-warn|param-property)
定义依据:description/CommonCompilerArguments.kt 在仓库中打开
怎么用
- 配置入口:build.gradle.kts → ohosArm64.binaries.all { freeCompilerArgs += "-Xannotation-default-target" }
- 示例:
// 文件:build.gradle.kts(应用的 Kotlin 模块,例如 composeApp)
kotlin {
ohosArm64 { // 按实际 native target 调整
binaries.all {
freeCompilerArgs += "-Xannotation-default-target"
}
}
}
- 生效:Sync 后执行该目标的 compile/link。
- 验证:编译日志出现 `-Xannotation-default-target`。
- 回滚:从 binaries.all 的 freeCompilerArgs 中删除该项后 Clean 并重编。
- 注意:实验项无稳定兼容保证;改前留可回滚配置。
默认行为 未设置
不写这个配置时,编译器会怎么处理?
此选项默认未设置(空列表 / 空映射 / null)。不设置时由其他逻辑决定行为或直接跳过。
未指定则为空。