Gradle - 从.properties文件加载属性

时间:2016-03-09 19:39:42

标签: gradle build.gradle

尝试在db.properties文件

中添加build.gradle文件时出现此错误

的build.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.properties:

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

1 个答案:

答案 0 :(得分:3)

如果您要从.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']