I need to execute from Gradle an Ant script which relies on environment variables.
Ant uses <property environment="env"/>
for it.
I tried to do env.foo="bar"
in Gradle, but it throws a Groovy exception.
What is the proper way to pass environment variables from Gradle to Ant?
From the gradle 2.0 docs, i see something like this is possible
Or in this case could use this
It is impossible to set environment variables from Gradle or JVM in general, but it is possible to trick Ant like this:
Accepted solution from @Sergey:
Does not work for me on
gradle
2.9 andant
1.9.7. That did not thrown any error, but do nothing. Indeed if you are look at code it implemented as:where org.apache.tools.ant.PropertyHelper#getProperties is:
So it make explicit copy and it can't work.
The way do it correctly in
gradle
file:Documentation mention few other ways (note, without project):