如何将一个gradle任务包装到另一个任务中? [英] How do I wrap a gradle task in another task?

查看:163
本文介绍了如何将一个gradle任务包装到另一个任务中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图配置两个不同的gradle测试任务,基本上只是设置一些值,然后运行内置的测试任务。我已经阅读了Gradle文档,并且一直在寻找几个小时而没有运气。我猜我只是不知道如何正确地说出这个问题来找到任何东西。



这个场景是我们有selenium测试,我们可能想在本地运行或远程。如果我们在本地运行它们,我们希望配置它使用的线程数量,如果我们远程运行它们,我们希望设置更多的线程和系统属性,以便测试运行器知道远程运行。



基本上就是我想要做的事情:

  task testLocal {
maxParallelForks = 2
//现在运行内置的测试任务
}

任务testRemote {
maxParallelForks = 4
systemPropertiesgeb. env:winxp-firefox
//现在运行内置的测试任务
}

理想情况下,我还希望能够通过测试任务在命令行上支持的所有参数,如:

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



用gradle处理这种情况的正确方法是什么?

解决方案

正确的处理方法是有两个 Test 塔斯KS。您通常会使用(并配置)Java插件的 test 任务来进行本地测试,并且另外声明并配置第二个 testRemote task( task testRemote(type:Test){...} )。 (没有办法包装任务,或从另一个任务调用任务。)


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?

解决方案

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

这篇关于如何将一个gradle任务包装到另一个任务中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆