【问题标题】:Grouping/inheriting properties for tasks in GradleGradle 中任务的分组/继承属性
【发布时间】:2015-02-11 16:05:49
【问题描述】:

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

【问题讨论】:

    标签: properties gradle task


    【解决方案1】:

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

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

    那么executable 可以是例如简称:

    propGroup.options.forkOptions.executable
    

    【讨论】:

      猜你喜欢
      • 2011-04-04
      • 1970-01-01
      • 1970-01-01
      • 2014-02-03
      • 2012-05-08
      • 1970-01-01
      • 2011-06-13
      • 2022-07-27
      • 2022-01-17
      相关资源
      最近更新 更多