You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Gradle Java插件:compileJava配置的Groovy DSL转Kotlin DSL等价写法

Gradle Kotlin DSL 等价写法

对应你提供的Groovy DSL配置,Gradle Kotlin DSL的等价写法如下:

tasks.compileJava {
    options.compilerArgs += listOf(
        "-Amapstruct.suppressGeneratorTimestamp=true",
        "-Amapstruct.suppressGeneratorVersionInfoComment=true",
        "-Amapstruct.verbose=true"
    )
}

如果需要适配所有JavaCompile类型的任务(不止compileJava),可以用更通用的写法:

tasks.withType<JavaCompile> {
    options.compilerArgs.addAll(
        listOf(
            "-Amapstruct.suppressGeneratorTimestamp=true",
            "-Amapstruct.suppressGeneratorVersionInfoComment=true",
            "-Amapstruct.verbose=true"
        )
    )
}

说明

Groovy DSL里可直接用+= [ ... ]添加集合元素,而Kotlin是强类型语言,需要通过listOf()明确创建列表,再用+=或addAll()将元素添加到编译器参数列表中。

内容的提问来源于stack exchange,提问作者Khaski

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.25 03:04:59