flyway gradle 插件,具有 groovy 环境
flyway gradle plugin with groovy environments
我正在尝试自定义 gradle 以构建以从 groovy 文件
获取飞行路线属性
我的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: Build failed with an exception.
* What went wrong: Execution failed for task ':flywayInfo'.
Error occurred while executing flywayInfo Unknown prefix for location (should be either filesystem: or classpath:): :**
谁能帮我提供位置。因为我需要根据环境提供多个位置
谢谢
你试过了吗:
locations = config.flywayProperties.locations
?
我遇到了同样的错误类型导致的问题。鉴于 String
但 String[]
预期。
请这样修改
locations = "${config.flywayProperties.locations}".split(',')
下一个问题是为什么粘贴的时候出现异常?
因为从 String
到 String[]
的强制转换会导致有线问题。例如,
(String[])"filesystem:xxx"
=> [f, i, l, e, s, y, s, t, e, m, :, x, x, x]
嗯,真的有线。所以当我们查看飞路位置代码时,一切都会清楚 here。
[f, i, l, e, s, y, s, t, e, m, :, x, x 中的 :
除外,将跳过所有单个单词 String
, x]
normalizedDescriptor
是 :
,它将作为不匹配 filesystem
或 classpath
.
的信号抛出
我正在尝试自定义 gradle 以构建以从 groovy 文件
获取飞行路线属性我的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: Build failed with an exception. * What went wrong: Execution failed for task ':flywayInfo'.
Error occurred while executing flywayInfo Unknown prefix for location (should be either filesystem: or classpath:): :**
谁能帮我提供位置。因为我需要根据环境提供多个位置
谢谢
你试过了吗:
locations = config.flywayProperties.locations
?
我遇到了同样的错误类型导致的问题。鉴于 String
但 String[]
预期。
请这样修改
locations = "${config.flywayProperties.locations}".split(',')
下一个问题是为什么粘贴的时候出现异常?
因为从 String
到 String[]
的强制转换会导致有线问题。例如,
(String[])"filesystem:xxx"
=> [f, i, l, e, s, y, s, t, e, m, :, x, x, x]
嗯,真的有线。所以当我们查看飞路位置代码时,一切都会清楚 here。
[f, i, l, e, s, y, s, t, e, m, :, x, x 中的 :
除外,将跳过所有单个单词 String
, x]
normalizedDescriptor
是 :
,它将作为不匹配 filesystem
或 classpath
.