如何将一个gradle任务包装到另一个任务中?

编程入门 行业动态 更新时间:2024-10-17 14:12:41
本文介绍了如何将一个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任务包装到另一个任务中?

本文发布于:2023-11-12 10:40:23,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何将   gradle

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!