piero
piero

Reputation: 11

Grouping/inheriting properties for tasks in Gradle

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

Upvotes: 1

Views: 515

Answers (1)

Opal
Opal

Reputation: 84844

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

Upvotes: 1

Related Questions