且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从 Gradle 构建中设置环境变量?

更新时间:2022-01-24 22:23:58

对于测试任务,可以使用 环境属性 像这样:

For a test task, you can use the environment property like this:

test {
  environment "VAR", "val"
}

您还可以使用 环境属性 在 exec 任务中

you can also use the environment property in an exec task

task dropDatabase(type: Exec) {
    environment "VAR", "val"
    commandLine "doit"
}

请注意,使用此方法,环境变量仅在任务期间设置.

Note that with this method the environment variables are set only during the task.