Gradle - Loading properties from a .properties file

I get this error when trying to add file db.propertiesto filebuild.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

The error I am getting is:

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

* What went wrong:
A problem occurred evaluating script.
> Could not find property 'blal' on root project 'CamelExtractionServices'.
+4
source share
1 answer

If you want to load properties from a file .properties, I would try something like this:

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

Then you can access your properties:

println additionalProperties['db']
println someOtherProperties['bar']
+3
source

All Articles