我正在尝试自定义 gradle 来构建以从 groovy 文件中获取 flyway 属性
我的 environment.groovy 文件
environments {
dev {
flywayProperties {
driver="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:@localhost:1521/XE"
user="test"
password="test"
locations= "classpath:db/migration,db/insert"
}
}
qa {
flywayProperties {
driver = "oracle.jdbc.driver.OracleDriver"
url = "jdbc:oracle:thin:@localhost:1521/XE"
user = "test"
password = "test"
locations = "classpath:db/migration"
}
}
}
和我的 build.gradle
loadConfiguration()
task printProps << {
println "Driver: $config.flywayProperties.driver"
println "URL: $config.flywayProperties.url"
println "User: $config.flywayProperties.user"
println "Password: $config.flywayProperties.password"
println "Locations: $config.flywayProperties.locations"
}
def loadConfiguration() {
def environment = hasProperty('env') ? env : 'dev'
project.ext.envrionment = environment
println "Environment is set to $environment"
def configFile = file('environment.groovy')
println configFile.toURL()
def config = new ConfigSlurper("$environment").parse(configFile.toURL())
project.ext.config = config
}
flyway {
driver = "$config.flywayProperties.driver"
url = "${config.flywayProperties.url}"
user = "${config.flywayProperties.user}"
password = "${config.flywayProperties.password}"
//locations = ['classpath:db/migration' , 'db/insert'] -- Works fine
locations = "${config.flywayProperties.locations}" -- Throws below error
}
当我尝试执行“gradle flywayInfo”时出现以下错误
**FAILURE:构建失败并出现异常。* 出了什么问题:任务 ':flywayInfo' 执行失败。
执行 flywayInfo 位置的未知前缀时发生错误(应该是文件系统:或类路径:)::**
有人可以帮助我如何提供位置。因为我需要根据环境提供多个位置
谢谢