I have code like the following in build.gradle.kts
:
fun setSystemProperty(ctx: Test, propName: String) {
val propValue = checkNotNull(project.findProperty(propName)) {
"Please set project property `$propName`"
}
ctx.systemProperty(propName, propValue)
}
tasks {
integrationTest {
doFirst {
setSystemProperty(this as Test, "foo")
setSystemProperty(this as Test, "bar")
}
}
}
IDEA warns “No cast needed” about the second setSystemProperty
call: is this because this as Test
actually mutates this
? I’m not sure if I’m doing this right.
What I actually want is to be able to require a number of parameters to be passed on the command-line (or via env vars) for my integration tests. These parameters are things like tokens for APIs. Is there a better way to do this?
I want nice error messages if users don’t set the right properties, not just a generic error, hence checkNotNull
.