Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I wrap a gradle task in another task?

Tags:

gradle

I am trying to configure two different gradle test tasks that essentially just set some values and then run the built-in test task. I have read the gradle documentation and have been searching for a few hours with no luck. I'm guessing I just don't know how to word this question properly to find anything.

The scenario is that we have selenium tests that we might want to run locally or remotely. If we run them locally we want to configure how many threads it uses, and if we run them remotely we want to set a much higher number of threads and also a system property so that the test runner knows to run remotely.

Essentially here's what I'd like to do:

task testLocal {
    maxParallelForks = 2
    // now run the built-in test task
}

task testRemote {
    maxParallelForks = 4
    systemProperties "geb.env": "winxp-firefox"
    // now run the built-in test task
}

Ideally I'd also like to be able to pass all the same arguments that the test task supports on the command line, like:

gradle testLocal --tests com.domain.tests.package*

What is the proper way to handle this scenario with gradle?

like image 677
nerdherd Avatar asked Oct 21 '25 12:10

nerdherd


1 Answers

The proper way to handle this is to have two Test tasks. You'd typically use (and configure) the Java plugin's test task for the local testing, and additionally declare and configure a second testRemote task (task testRemote(type: Test) { ... }). (There is no way to "wrap" a task, or "call" a task from another task.)

like image 194
Peter Niederwieser Avatar answered Oct 23 '25 08:10

Peter Niederwieser



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!