如何重用 Gradle 中的任务配置?
How do I reuse task configuration in Gradle?
我的任务 war 配置有很多 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。
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
}
我的任务 war 配置有很多 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。
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
}