Q: How do I reuse task configuration in Gradle? I have task war configuration with many from/include/exclude:
task war {
    exclude
    exclude
    ... 
    into ... from ... 
    into ... from ... 
}

I have another task war configuration which is the same except one exclude.
I don't want to duplicate those configurations. How can I reuse the first configuration?

A: Try:
ext.sharedCopyConf = { task, to ->
  configure(task) {
    into to
    from 'a'
  }
}

task copy1(type: Copy) { t ->
  sharedCopyConf(t, 'b')
}

task copy2(type: Copy) { t ->
  sharedCopyConf(t, 'c')
}

Have a look at the demo.

A: ext.sharedWarConfig = { task->
    configure(task) {
        from ... include ...

    }}

task warWithoutFile(type: War) {  task ->
    sharedWarConfig(task)

    exclude ...
}

task warWithFile(type: War) {   task -> sharedWarConfig(task) }

jettyRunWar {
    dependsOn warWithFile
    dependsOn.remove("war")

    webApp = warWithFile.archivePath
}

