For example: I generate a file with build information (SVN branch, revision, build date) and include that in my build. Now I'd like to include the value of an environment variable in that file and have Gradle recognize that variable as a dependency. How can I do that?
I can always write the variable to a file and depend on that. Is there an easier way without the extra file?
Same way you would in any Java (or Groovy) code.
System.getenv().get("ENV_VAR_NAME")
When you say have a task "depend on" a variable I assume you mean in terms of incremental build support. If you want to have your task run again if the environment variable changes, you can specify it as a task input.
task myTask {
inputs.property 'myVar', System.getenv().get("MY_VAR")
}
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