如何在gradle.build中使用resources / application.properties中配置的属性?我想得到这样的东西:
flyway {
url = MAP_WITH_PROPERTIES['spring.datasource.url']
user = MAP_WITH_PROPERTIES['spring.datasource.username']
}
答案 0 :(得分:4)
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']
答案 1 :(得分:1)
您可以加载属性并以这种方式使用它们:
ext.ApplicationProps = new Properties()
ApplicationProps.load(new FileInputStream("src/main/resources/application.properties"))
使用如下:
flyway {
url = ApplicationProps['spring.datasource.url']
user = ApplicationProps['spring.datasource.username']
}
请注意,属性的路径是从根目录定义的,如果您有多模块项目,可能会有所不同。