如何在gradle java构建脚本中访问环境变量 [英] How to access environment variables in gradle java build script

查看:540
本文介绍了如何在gradle java构建脚本中访问环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在gradle java构建脚本中访问环境变量(用户级别或系统级别)。

我是gradle新手,我正在尝试使用gradle构建项目。
目前我已经对第三方jar的路径进行了硬编码,如下面的脚本所示

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'
   }
}

我在环境变量中创建了一个环境变量Third_Party:

I have created an environment variable "Third_Party" in enviroment variable:

Third_Party=D:\lib

如何使用此变量,即Third_Party而不是硬编码脚本中的库路径。

请告诉确切的语法

How can I use this variable i.e. "Third_Party" instead of hardcoding the library path in script.
Please tell the exact syntax

推荐答案

试试这种方式 System.getenv(env var name) like

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')
}

这篇关于如何在gradle java构建脚本中访问环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆