Reputation: 1265
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'.
Upvotes: 5
Views: 14532
Reputation: 48903
The better way is to utilize withInputStream
which automatically close
es a stream:
def props = new Properties()
File propsFile = file("local.properties")
if (propsFile.isFile()) {
propsFile.withInputStream { props.load(it) }
} else {
props.put("key", "defaultValue");
}
Upvotes: 0
Reputation: 23795
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']
Upvotes: 4