Gradle - 从 .properties 文件加载属性

标签 gradle build.gradle

尝试在 build.gradle 文件中添加 db.properties 文件时遇到此错误

构建.gradle:

allprojects {

    apply from: 'db.properties'
    apply from: 'deployment.properties'

    repositories {
        mavenCentral()
    }

    apply plugin: 'java'
    apply plugin: 'war'
    apply plugin: 'maven-publish'
    apply plugin: 'idea'

    sourceCompatibility = 1.8

}

数据库属性:

db=blal
dbUsername=/bilal/home

我得到的错误是:

* Where:
Script 'camelawsextractionservicesb/db.properties' line: 1

* What went wrong:
A problem occurred evaluating script.
> Could not find property 'blal' on root project 'CamelExtractionServices'.

最佳答案

如果您希望从 .properties 文件加载属性,我会尝试这样的操作:

ext.additionalProperties = new Properties().load(file("db.properties").newReader())
ext.someOtherProperties = new Properties().load(file("foo.properties").newReader())

然后您可以访问您的属性:

println additionalProperties['db']
println someOtherProperties['bar']

关于Gradle - 从 .properties 文件加载属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35901072/

相关文章:

android - 新依赖 React native - gradle clean - 无法解析所有依赖

android - 如何启用 github 操作访问 gradle 属性?

android - 意外的顶级异常 : com. android.dex.DexException:多个 dex 文件定义 Landroid/support/annotation/AnimRes

android - 在 build.gradle 中找不到参数的方法 uploadArchives()

android - 更新PlayService版本为12.0.0后无法运行应用

java - gradle-在根项目 'customjrxml'中找不到项目 'customjrxml'

gradle - 有没有办法使用 gradle 6.0 定义要在 settings.gradle.kts 和项目/子项目 build.gradle.kts 中使用的属性?

android - 更新 gradle 依赖项后呈现问题

gradle - 设置从 build.gradle 内的 local.properties 读取的属性

android - 无法从android studio上的github导入项目