Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle task definition inheritance

Tags:

gradle

groovy

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?

like image 697
mawek Avatar asked Dec 11 '12 16:12

mawek


1 Answers

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...

like image 200
Hiery Nomus Avatar answered Oct 27 '22 15:10

Hiery Nomus