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

时间:2015-02-11 16:05:49

标签: properties gradle task

有没有办法在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中的任务继承任务

1 个答案:

答案 0 :(得分:1)

如果propGroup被定义为地图,它将起作用:

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

然后executable可以是例如简称:

propGroup.options.forkOptions.executable