gradle - 在运行已经完成的任务之前构建 Gradle getProperties
问题描述
我正在尝试使用 gradle 版本 4.8+ 的 Java、Serenity-BDD 项目,但应用程序没有提取 -Denvironment 和 -Dservicebranches 的 CLI 参数。我将这些属性作为我的 local.properties 文件中的空白值,并且在我的应用程序运行时它们没有被分配。
- ./gradlew --build-cache build -Dwebdriver.remote.url=${SELENIUM_REMOTE_URL} -Denvironment=${ENVIRONMENT} -Dservicebranches=${SERVICE_BRANCHES} -Dtags=${TAGS}
我有一个 local.properties 文件,其中的属性被成功地依赖注入到项目中(通过 Serenity-Spring)。我希望这些 CLI 参数将覆盖这些值:
servicebranches=
environment=local
但是现在,CLI 参数中指定的任何内容都没有传递到项目中。通过 DI,或者通过显式获取 build.gradle 中的环境变量,我尝试过的方法没有奏效。
这是我在 build.gradle 中尝试过的一些事情:
//task integrationTests() {
// doFirst
// {
// def environment = System.getProperty('environment')
// def servicebranches = System.getProperty('servicebranches')
// }
// tasks.build.execute()
//}
//integrationTests.dependsOn(build)
//build.doFirst{
// systemProperties System.properties
// def environment = System.properties['environment']
// environment = environment //This actually flags with 'Silly assignment'
//}
build.doFirst{
def environment = System.getProperty('environment')
def servicebranches = System.getProperty('servicebranches')
}
最新的似乎仍然缺少一步,因为程序仍在运行,但 args 仍然没有通过。我什至尝试过 -Denvironment=potato,但没有出现任何错误,因为我没有名为该名称的属性或属性文件。
我也尝试过使用 -P 标签而不是 -D 标签,但这似乎也不起作用。
我要做的就是使用 build.gradle 来使用 System.getProperty('environment') 和 System.getProperty('servicebranches'),然后再使用 Serenity 附带的已创建的“构建”任务。我该怎么做?我是否构建了一个全新的任务,在其中使用这些 getProperties,然后调用构建任务?我是否必须在 local.properties 文件中指定这些相同命名变量的分配?
解决方案
-D 用于 Gradle 中的系统属性。尝试使用 -P 代替(https://docs.gradle.org/current/userguide/build_environment.html#sec:project_properties)
推荐阅读
- javascript - React 中的普通 ES6 类
- google-bigquery - 从 bigquery 数组中获取所有长度为 3 的窗口
- elixir - Edeliver Phoenix 发布失败
- scala - Scala 类型等价性检查单例类型
- javascript - 在页面加载时获取图像
- c++ - 致命错误:Wt/WApplication.h:没有这样的文件或目录
- node.js - node.js - 如何在不阻塞父进程的标准输入的情况下生成子进程?
- r - 通过重复列表 R 计算所有排列
- javascript - $("的javascript等价物是什么?
- angular - No component factory found for undefined. but did add to @NgModule.entryComponents with SharedModule