Reputation: 243
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
Upvotes: 18
Views: 39057
Reputation: 845
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')
}
Upvotes: 36