在Gradle Kotlin DSL中,相当于Groovy DSL中的`compilerArgs`用于`compileJava`的是什么?

huangapple go评论61阅读模式
英文:

Gradle Kotlin DSL equivalent for Groovy DSL compilerArgs for compileJava?

问题

对于Gradle的Java插件,以下是与上述Groovy DSL等效的Kotlin DSL:

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

For the Gradle Java plugin, what is the Kotlin DSL equivalent for the following Groovy DSL?

compileJava { 
  options.compilerArgs += [ 
    &#39;-Amapstruct.suppressGeneratorTimestamp=true&#39;, 
    &#39;-Amapstruct.suppressGeneratorVersionInfoComment=true&#39;, 
    &#39;-Amapstruct.verbose=true&#39;
  ]
}

答案1

得分: 0

tasks.compileJava {
  options.compilerArgs.addAll(
    listOf(
      &quot;-Amapstruct.suppressGeneratorTimestamp=true&quot;,
      &quot;-Amapstruct.suppressGeneratorVersionInfoComment=true&quot;,
      &quot;-Amapstruct.verbose=true&quot;,
    )
  )
}
英文:

compilerArgs is a Java List&lt;String&gt;, which in Kotlin is mapped to a MutableList&lt;String&gt;.

There are a few different ways to add elements to a mutable list in Kotlin. One option is to use addAll()

tasks.compileJava {
  options.compilerArgs.addAll(
    listOf(
      &quot;-Amapstruct.suppressGeneratorTimestamp=true&quot;,
      &quot;-Amapstruct.suppressGeneratorVersionInfoComment=true&quot;,
      &quot;-Amapstruct.verbose=true&quot;,
    )
  )
}

huangapple
  • 本文由 发表于 2023年4月10日 21:12:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/75977450.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定