I have an integration test task that’s set up via the JVM Test Suite plugin. I need to add an environment variable to this task. Previously, I would do this:
I tried to add the if block to the integrationTest(JvmTestSuite) closure, but evidently environment is unknown at that point. I could use a hammer and do
tasks.withType(JavaExec).configureEach {
if (!environment.get("FOO")) {
environment.put("FOO", "bar")
}
}
but that seems like it’d be overkill. Is there a different way to set the variable just for the integration test task that I’m missing?
Can you be more specific about “within the test suite’s block”? I tried within testing.suites.test.integrationTest, but in both cases Gradle said
Could not find method testTask() for arguments [build_e35hwv745lktfqdti46lzmcxr$_run_closure10$_closure38$_closure41$_closure45$_closure46@1d26da3a] on object of type org.gradle.api.plugins.jvm.internal.DefaultJvmTestSuiteTarget.
For more completeness, here’s the full testing closure: