Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Yes, it is possible to set an environment variable or property in Gradle only within the test environment. One way to achieve this is by using the test task in the Gradle build script.

For example, you can set a system property only during the execution of the test task as follows:

test {
    systemProperty 'test.environment', 'test'
}

In this example, the system property test.environment is set to test only during the execution of the test task. This can be used to differentiate between the production and test environments in your code.

Alternatively, you can use the testEnvironment block in the Gradle build script to set environment variables only for the test environment. For example:

testEnvironment {
    environmentVariables {
        'TEST_ENV': 'test'
    }
}

In this example, the environment variable TEST_ENV is set to test only for the test environment. This can be used to configure your tests to run differently based on the environment.