if (project.hasProperty('special'))
应该这样做。
请注意,您选择testng套件所要执行的操作将不起作用,AFAIK:测试任务没有任何test()
方法。有关工作示例,请参阅https://discuss.gradle.org/t/how-to-run-acceptance-tests-with-testng-from-gradle/4107:
test {
useTestNG {
suites 'src/main/resources/testng.xml'
}
}
@ user2506293,这还不够。您需要检查project是否具有属性以及是否已设置。
这很糟糕@Opal-null会导致false,因此您无需显式检查。
@ th3morg这是错误的,如果属性存在但为null,则hasProperty(..)仍将返回true,因此,
if (project.hasProperty('special') && project.special)
如果要同时检查是否存在而不是null,则必须使用。