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!
Gradle can also set project properties when it sees specially-named system properties or environment variables. If the environment variable name looks like ORG_GRADLE_PROJECT_prop=somevalue , then Gradle will set a prop property on your project object, with the value of somevalue .
Gradle project properties provide an easy way to customise builds which may need to run differently in certain situations. In this article you'll learn the most effective ways to use and set properties, along with some common scenarios you might come across in your Gradle project.
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
.
Not all environment variables are visible to gradle. If you can name them with the special prefix ORG_GRADLE_PROJECT_
these will be available. You can read about it here
ORG_GRADLE_PROJECT_foo
can be accessed as foo
within gradle.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With