问题
Is there a way to reuse property groups in Gradle?
Something that would look like:
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)
}
In Java that would be inheritance but you cannot inherit a task from a task in Gradle
回答1:
It will work if propGroup
would be defined as a map:
def propGroup = [
options: [
fork: true,
forkOptions: [
executable: true
]
]
]
Then executable
could be e.g. referred as:
propGroup.options.forkOptions.executable
来源:https://stackoverflow.com/questions/28458928/grouping-inheriting-properties-for-tasks-in-gradle