How to pass System Properties to Test task lazy? I...
# community-support
k
How to pass System Properties to Test task lazy? I tried using ValueSource as provider:
Copy code
tasks.named("test", Test::class.java) { test ->
                test.systemProperty(PACT_BROKER_URL, ALPHA_PACT_BROKER_URL)
                test.systemProperty(PACT_BROKER_ENABLE_PENDING, true)
                test.systemProperty(PACT_BROKER_INCLUDE_WIP_PACTS_SINCE, "2023-10-19")
                test.systemProperty(PACT_PROVIDER_NAME, project.versionProvider.map { it[ALPHA_VERSION_FILE_PROPERTY_NAME].orEmpty() })
                test.systemProperty(PACT_PROVIDER_VERSION, project.versionProvider.map { it[ALPHA_VERSION_FILE_PROPERTY_VERSION].orEmpty() })
                test.systemProperty(PACT_PROVIDER_BRANCH, project.versionProvider.map { it[ALPHA_VERSION_FILE_PROPERTY_GIT_COMMIT_BRANCH].orEmpty() })
                test.systemProperty(PACT_VERIFIER_PUBLISH_RESULTS, System.getProperty(PACT_VERIFIER_PUBLISH_RESULTS))
            }
But in the debugger those properties are never resolved properly:
t
k
I was worried that this will be the same old hack that we are using for version 😉
Copy code
class Version(private val version: Provider<SemVer>) {
    override fun toString(): String {
        return version.get().toString()
    }
}
Thanks anyway :)
v
Actually, you can do differently, but the
toString
-lazy also works. Hopefully with the propertization in Gradle 9 this will change anyway. The alternative you could use is an argument provider.
This is especially then helpful when the values you construct the arguments from should also be task inputs