gradle - 如何在 Gradle 中重用任务配置?

标签 gradle task code-reuse

我有许多 from/include/exclude 任务战配置:

task war {
    exclude
    exclude
    ... 
    into ... from ... 
    into ... from ... 
}

我有另一个任务 war 配置,除了一个exclude 之外是相同的。 我不想重复这些配置。如何重用第一个配置?

最佳答案

尝试:

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')
}

看看 demo .

关于gradle - 如何在 Gradle 中重用任务配置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37713363/

相关文章:

java - 使用 gradle 通过 for 循环任务调用创建多 Jar

testing - 无法实例化规范 'KernelTest'

c# - 任务始终处于等待激活状态(查找所有串行设备)

javascript - 避免用多种不同的语言编写相同的算法

javascript - HTML SVG 重用组 <g> 和 <use> 并为每个实例单独更改内部元素的属性

Gradle :Could not create service of type FileHasher

gradle - 当使用标准生命周期插件已被弃用并计划在 Gradle 3.0 中删除时,定义自定义 ‘build’ 任务已被弃用

后台的 Android 异步任务进度

c# - 任务并行性 - 任务 OnCompleted 在所有ContinueWith之后触发

refactoring - 代码重用和重构