Setting environment variables from Gradle


#1

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?


(Peter Niederwieser) #2

Gradle, and more generally the JDK, doesn’t support setting environment variables from inside the process. I’d consider tweaking the Ant script, calling Ant as an external process (e.g. via JavaExec), or setting the environment variable externally.


(Adam Murdoch) #3

You could fake it, by doing something like:

ant.properties['env.foo'] = 'bar'

#4

Thanks a lot!

That’s exactly what I was searching for.