Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print the environment map for Gradle test task

With Java plugin test task in Gradle, how can I print the environment map for the JVM process which executes the tests.

test.doFirst {
        environment 'KAFKA_PORT', "${KAFKA_TCP_9902}"
        environment 'DB_PORT', "${MYSQL_TCP_3306}"
        // How to print the map of all environments set so far?
}
like image 452
Ashish Tyagi Avatar asked Jan 30 '23 22:01

Ashish Tyagi


1 Answers

You can access the environment map directly. Just loop through it and print the values over the keys:

test.doFirst {
    [...] // do something
    environment.each { k, v -> println "${k}:${v}" }
}

Both the map property and two methods to add values, one of them you use, are named environment. By default, the environment variables from the Gradle process are used.

like image 76
Lukas Körfer Avatar answered Feb 02 '23 11:02

Lukas Körfer