Gradle任务检查是否定义了属性 [英] Gradle task check if property is defined
问题描述
我有一个gradle任务,它执行一个testng测试套件. 我希望能够将标志传递给任务,以便使用特殊的testng xml套件文件(如果未设置标志,则仅使用默认套件).
I have a gradle task that executes a testng test suite. I want to be able to pass a flag to the task in order to use a special testng xml suite file (or just use the default suite if the flag isn't set).
gradle test
应运行默认的标准测试套件
Should run the default standard suite of tests
gradle test -Pspecial
应该运行特殊的测试套件
Should run the special suite of tests
我一直在尝试这样的事情:
I've been trying something like this:
test {
if (special) {
test(testng_special.xml);
}
else {
test(testng_default.xml);
}
}
但是出现未定义的属性错误.解决这个问题的正确方法是什么?
But I get a undefined property error. What is the correct way to go about this?
推荐答案
if (project.hasProperty('special'))
应该这样做.
请注意,您选择Testng套件所要执行的操作将不起作用,AFAIK:测试任务没有任何test()
方法.请参阅 https://discuss.gradle.org/t/how-to-to-to-testing-testing-to-gradle/4107 :
Note that what you're doing to select a testng suite won't work, AFAIK: the test task doesn't have any test()
method. Refer to https://discuss.gradle.org/t/how-to-run-acceptance-tests-with-testng-from-gradle/4107 for a working example:
test {
useTestNG {
suites 'src/main/resources/testng.xml'
}
}
这篇关于Gradle任务检查是否定义了属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!