How can I access environment variables (either user level or system level) in gradle java build script.
I am new to gradle and I am trying to build my project using the gradle.
Presently I have hardcoded the path of third party jars as shown in the script below
repositories {
flatDir {
dirs 'D:\\lib'
}
}
I have created an environment variable "Third_Party" in enviroment variable
:
Third_Party=D:\lib
How can I use this variable i.e. "Third_Party" instead of hardcoding the library path in script.
Please tell the exact syntax
Enabling Environment Variables in Gradle Android developers can use environment variables using Gradle's module-level build configuration. This module-level Gradle configuration file lets you specify build settings for that application module.
gradle file is located inside your project folder under app/build. gradle.
try this way System.getenv("env var name")
like
home = System.getenv('Third_Party')
task env_read << {
println "$System.env.HOME"
//Other way of accessing the environment variable.
println System.getenv('Third_Party')
}
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