Noel Yap
Noel Yap

Reputation: 19758

How to refactor common Gradle task configurations?

I have something like the following:

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`
}

How can I avoid duplication of the 'bunch of common config stuff'?

Upvotes: 2

Views: 273

Answers (2)

Peter Niederwieser
Peter Niederwieser

Reputation: 123890

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

test { ... }

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

Upvotes: 4

WojciechKo
WojciechKo

Reputation: 1531

You can use methods: 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
}

Upvotes: -1

Related Questions