分组/继承Gradle中任务的属性



有办法在Gradle中重用属性组吗?

看起来像:

def propGroup = [
 options.fork = true
 options.forkOptions.executable = ...
]
task compileThis(type:JavaCompile) {
  options.fork = propGroup.options.fork
  options.forkOptions.setExecutable(propGroup.options.forkOptions.executable)
  destinationDir = file(xxx)
}
task compileThat(type:JavaCompile) {
  options.fork = propGroup.options.fork
  options.forkOptions.setExecutable(propGroup.options.forkOptions.executable)
  destinationDir = file(yyy)
}

在Java中,这将是继承,但不能从Gradle 中的任务继承任务

如果propGroup被定义为映射,它将起作用:

def propGroup = [
   options: [
      fork: true,
      forkOptions: [
         executable: true
      ]
   ]
]

executable可以例如被称为:

propGroup.options.forkOptions.executable

最新更新