【问题标题】:specify gradle properties file as command line argument to gradlew将 gradle 属性文件指定为 gradlew 的命令行参数
【发布时间】:2019-09-04 16:32:40
【问题描述】:

我正在开发一个项目,其中每个环境都有不同的 gradle.properties 文件。该过程似乎是根据需要将 gradle.properties.env(例如)重命名为 gradle.properties。

我是 Gradle 的新手,所以这可能是更广泛的错误方法,但现在,有没有办法告诉 ./gradlew 使用特定文件作为其 gradle.properties,例如

./gradlew --propertiesfile=gradle.properties.env 

【问题讨论】:

    标签: gradle gradlew


    【解决方案1】:

    最好将环境特定的属性文件放在GRADLE_USER_HOME 文件夹中(默认为$USER_HOME/.gradle)。此位置的配置优先于项目文件夹中的配置。

    另一种选择是将各个属性作为系统属性或环境变量提供。

    【讨论】:

    • gradle.properties 文件只包含环境变量 - 我假设 Gradle 不能在配置文件中传递,那么针对不同环境处理不同环境变量的最佳方法是什么?
    • 看起来像discuss.gradle.org/t/… 这样的东西可以工作:def envScript = file("gradle/$environment-env.gradle") if (!envScript.exists()) { throw new GradleException("Unknown environment: $environment") } apply from: envScript
    猜你喜欢
    • 2018-02-09
    • 1970-01-01
    • 2016-05-14
    • 2012-04-16
    • 2018-11-29
    • 1970-01-01
    • 1970-01-01
    • 2011-01-06
    • 2023-03-24
    相关资源
    最近更新 更多