如何在build.gradle中配置飞行路线以从其他属性文件中获取url,用户名,密码?
取而代之的是:
flyway {
url = 'jdbc:postgresql://localhost:5432/db'
user = 'a'
password = 'a'
locations = ['filesystem:db/migration']
}
像这样:
flyway {
path = ['filesystem:src/main/resources/data-access.properties']
locations = ['filesystem:db/migration']
}
你可以做这样的事情:
ext.flywayProps = new Properties()
flywayProps.load(new FileInputStream(this.projectDir.absolutePath + "/src/main/resources/data-access.properties"))
在构建脚本的根目录中,它会将属性文件加载到Properties
类型的局部变量中。之后,您可以根据需要使用此属性,例如:
flyway {
url = 'jdbc:postgresql://flywayProps['dbIp']:flywayProps['dbPort']/db'
user = flywayProps['dbUsername']
password = flywayProps['dbPassword']
locations = ['filesystem:db/migration']
}
在您的data-access.properties
中,您需要指定如下:
dbIp=localhost
dbPort=5432
dbUsername=a
dbPassword=a