Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle: how can I make a task depend on an environment variable?

Tags:

gradle

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?

like image 404
Robert Avatar asked Oct 19 '25 05:10

Robert


1 Answers

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")
}
like image 157
Mark Vieira Avatar answered Oct 22 '25 08:10

Mark Vieira



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!