0

I created a custom Gradle task for running from terminal in a separate file named feature.gradle, based on this answer and Gradle docs

task("withFeature", JavaExec::class) {
    group = "myCustomTasks"
    main = "com.example.calculator"
    classpath = sourceSets["main"].runtimeClasspath
    args(feature)

}

and register task in Gradle

tasks.register("withFeature")

feature is a property (string) that I want to pass into test (for now it's unit test, but later it would be android UI test)

    @Test
    fun getPackArgs() {
        val property = System.getProperty("feature")
        Assert.assertEquals("default", property)
    }

But when i write next command, where -Pfeature=default is what i wants to pass into code

./gradlew test withFeature -Pfeature=default

test fails, and System.getProperty("feature") is null :

expected:<default> but was:<null>
Expected :default
Actual   :null

Can anyone elaborate what i am doing wrong while running task with argument, which should pass into test package ? Thanks in advance

AShX
  • 358
  • 3
  • 14
  • 1
    You are confusing system properties `-D` and project properties `-P` the latter you can access via `project.property("feature")`. Also `task("withFeature", JavaExec::class)` already declares the task so `tasks.register("withFeature")` is redundant/harmful. – user16358266 Aug 30 '22 at 15:30
  • @user16358266 Thanks for an answer, but how I can access project.property("feature") from the test package ? – AShX Aug 30 '22 at 16:07

0 Answers0