Reputation: 9331
How can I use properties configured in resources/application.properties in gradle.build? I would like to get something like this :
flyway {
url = MAP_WITH_PROPERTIES['spring.datasource.url']
user = MAP_WITH_PROPERTIES['spring.datasource.username']
}
Upvotes: 5
Views: 3435
Reputation: 28101
import java.util.Properties
def props = new Properties()
file('src/main/resources/application.properties').withInputStream {
props.load(it)
}
def url = props['spring.datasource.url']
def user = props['spring.datasource.username']
Upvotes: 9
Reputation: 28136
You can load properties and use them this way:
ext.ApplicationProps = new Properties()
ApplicationProps.load(new FileInputStream("src/main/resources/application.properties"))
And use it as follows:
flyway {
url = ApplicationProps['spring.datasource.url']
user = ApplicationProps['spring.datasource.username']
}
Just note, that path to the properties is defined from the root and may vary if you have a multimodule project.
Upvotes: 1