Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle - Load properties from a .properties file

I am getting this error while trying to add db.properties file in build.gradle file

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

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'.
like image 971
Bilal Shah Avatar asked Sep 26 '22 03:09

Bilal Shah


1 Answers

If you're looking to load properties from an .properties file, 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']
like image 195
RaGe Avatar answered Sep 29 '22 23:09

RaGe