Flyway + gradle + spring boot setup

How to set up flyway in build.gradle to get url, username, password from another properties file?

Instead of this:

flyway {
    url = 'jdbc:postgresql://localhost:5432/db'
    user = 'a'
    password = 'a'
    locations = ['filesystem:db/migration']
}

      

something like that:

flyway {
    path = ['filesystem:src/main/resources/data-access.properties']
    locations = ['filesystem:db/migration']
}

      

+3


source to share


1 answer


You can do something like this:

ext.flywayProps = new Properties()
flywayProps.load(new FileInputStream(this.projectDir.absolutePath + "/src/main/resources/data-access.properties"))

      

At the root of your build script, it will load the properties file into a local variable of type Properties

. After that, you can use these properties as you need, for example:



flyway {
    url = 'jdbc:postgresql://flywayProps['dbIp']:flywayProps['dbPort']/db'
    user = flywayProps['dbUsername']
    password = flywayProps['dbPassword']
    locations = ['filesystem:db/migration']
}

      

And in yours, data-access.properties

you need to specify it like this:

dbIp=localhost
dbPort=5432
dbUsername=a
dbPassword=a

      

+2


source







All Articles