How to avoid TestNG Factory Methods being called automatically in a gradle project?

I have several test classes defined in my gradle project and few classes define testng factory methods. I have defined several test tasks to run my tests, currently i am using below logic to load specific classes and run particular tests

task dummyTestTask(type:Test) {

scanForTestClasses=false

include ‘/functional//*.class’

useTestNG {

includeGroups(‘functional’)

} }

If i ignore setting the property scanForTestClasses, all of my factory methods are being called(which i want not to happen) Currently i have multiple test tasks defined, but i want to have only one test task but call few tests based on grouping the tests.

Please suggest some solution to this problem!