0

How can I create an "alias" for gradle property name?

For example, Android Instrumentation Runner provides an ability to execute only certain test class / method:

./gradlew connectedAndroidTest \
   -Pandroid.testInstrumentationRunnerArguments.class=com.example.TestSuiteName

How can I make this param name shorter?

I have tried creating custom task like this:

task executeTest {
    setProperty('android.testInstrumentationRunnerArguments.class', 'com.example.TestSuiteName')
    dependsOn 'connectedAndroidTest'
}

But it blows up with groovy.lang.MissingPropertyException.

The same is with using doLast {} closure.

Any suggestions?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Andrii Abramov
  • 10,019
  • 9
  • 74
  • 96

1 Answers1

0

In this case I believe your setting a property on the Project object, same as having project.setProperty('key', 'val'), but you want to add the property to the System.properties

Something like this should work to check if the task is to be executed first then set the system property.

gradle.taskGraph.whenReady { taskGraph ->
    if (taskGraph.hasTask("connectedAndroidTest") {
        System.setProperty('android.testInstrumentationRunnerArguments.class', 'com.example.TestSuiteName')
    }
}
JBirdVegas
  • 10,855
  • 2
  • 44
  • 50