Gradle task check if property is defined

Solution 1:

if (project.hasProperty('special'))

should do it.

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'
    }
}

Solution 2:

This worked for me:

test {
    if (properties.containsKey('special')) {
        test(testng_special.xml);
    }
    else {
        test(testng_default.xml);
    }
}