Applying properties to all tasks from an external gradle script task

plugins

(Rohan Palkar) #1

I have got a number of gradle scripts which have some tasks defined (tasks which trigger testng tests) and all of them require certain common system properties. Therefore, I created a separate gradle script which houses a task that sets these system properties for all tasks of a particular type -
common-test-properties.gradle’ >>

    task configureProps {
        testProperties.each { prop ->
            tasks.withType(Test){
                systemProperty propKey,propValue
            }
        }
    }

However, this common gradle script is not able to determine the tasks defined in my test-gradle scripts.
i.e.

gradle-script-test-1 >>

apply from : 'common-test-properties.gradle'
task 1-A (type : Test, dependsOn : ['configureProps']) {}
task 1-B (type : Test, dependsOn : ['configureProps']) {}

gradle-script-test-2 >>

apply from : 'common-test-properties.gradle'
task 2-A (type : Test, dependsOn : ['configureProps']) {}
task 2-B (type : Test, dependsOn : ['configureProps']) {}

So these test-tasks don’t get the system properties that are set by the common-test-properties.gradle file.

Could anyone please provide some pointer to resolve this and probably explain a bit what am I missing out here.
PS: I am relatively new to gradle so not profound in it.

Appreciate your inputs. Thanks.