mawek
mawek

Reputation: 709

Gradle task definition inheritance

Is it possible to inherit one task definition from another? What I want to do is create some test profiles, so I'd have default test -

test {

    include 'com/something/something/**'
    exclude 'com/something/else/**'

    maxParallelForks 5

    testLogging{
        exceptionFormat "full"
        showStackTraces = false
    }

    jvmArgs '-Xms128m', '-Xmx512m', '-XX:MaxPermSize=128m'
}

and some another test with overriden "include" or "maxParallelForks" part etc.

Is it possible without creating new Task class?

Upvotes: 11

Views: 6076

Answers (1)

Hiery Nomus
Hiery Nomus

Reputation: 17769

You could configure all those tasks in one go, provided they're of the same type using the following construct:

tasks.withType(Test) {
  include 'com/something/something/**
  ...
}

This configures all the tasks of type "Test" in one go. After that you can override the configurations.

or if you don't want to setup all the tasks, or some of them have a different type, you can enumerate them as in the following snippet.

["test","anotherTestTask"].each { name ->
  task "$name" {
    include ...
  }
}

Remember, you have the full scripting power of Groovy, so there are a lot of options here...

Upvotes: 13

Related Questions