Skip to content
Advertisement

Does gradle.properties have access to environment variables

I looked around and could not find any way of accessing environment variables in my gradle.properties.

What I can do: In my build.gradle I can access environment variables like this System.getenv("MY_VAR"). I would like to do the same in my gradle.properties.

Example of what I want to do: In my gradle.properties replace build.foo=bar with build.foo=System.getenv("BAR")

So far all my attempts to access environment variables from gradle.properties have failed.

Any insight into the matter would be great, thanks!

Advertisement

Answer

could not find any way of accessing environment variables in my gradle.properties.

You can’t. gradle.properties is not anything fancy, it is a standard properties file.

You would need to post-process the properties somehow as indicated in this. Currently, Gradle does not offer any such functionality to “custom load” gradle.properties.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement