Question

I would like to have a properties file that deployed with my application so that I can access it at runtime. How can I have my build.gradle file access my property file located in src/main/resources?

I would like to use this file as I would normal use gradle.properties.

Was it helpful?

Solution

You want to read this properties file in your build.gradle file? You can simply:

def props = new Properties()
file("src/main/resources/my.properties").withInputStream { 
    stream -> props.load(stream) 
}

OTHER TIPS

Here's a method if you want to load properties from an external .properties file and merge them with those from gradle.properties:

def loadExtraProperties(String fileName) {
    def props = new Properties()
    props.load(new FileInputStream(fileName))

    props.each { key, val ->
        project.set(key, val)
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top