Gradle中任务的分组/继承属性 [英] Grouping/inheriting properties for tasks in Gradle
本文介绍了Gradle中任务的分组/继承属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以重用Gradle中的属性组?
Is there a way to reuse property groups in 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中的任务继承任务
In Java that would be inheritance but you cannot inherit a task from a task in Gradle
推荐答案
如果将 propGroup
定义为地图,它将起作用:
It will work if propGroup
would be defined as a map:
def propGroup = [
options: [
fork: true,
forkOptions: [
executable: true
]
]
]
然后 executable
例如简称为:
propGroup.options.forkOptions.executable
这篇关于Gradle中任务的分组/继承属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文