如何重构常见的Gradle任务配置?

时间:2014-04-10 23:23:00

标签: gradle

我有以下内容:

test {
    // bunch of common config stuff

    // some config stuff specific to `test`
}

task integrationTest(type: Test) {
    // bunch of common config stuff

    // some config stuff specific to `integrationTest`
}

如何避免重复使用常见的配置内容?

2 个答案:

答案 0 :(得分:4)

tasks.withType(Test) {
    // common stuff
}

test { ... }

task integrationTest(type: Test) { ... }

答案 1 :(得分:-1)

您可以使用以下方法:http://www.gradle.org/docs/current/userguide/userguide_single.html

test {
    config()
    // some config stuff specific to `test`
}

task integrationTest(type: Test) {
    config()
    // some config stuff specific to `integrationTest`
}

void config() {
    // bunch of common config stuff
}