[英]flyway gradle plugin with groovy environments
I am trying to customize gradle to build to get flyway properties from groovy file我正在尝试自定义 gradle 以构建以从 groovy 文件中获取 flyway 属性
my environment.groovy file我的 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"
}
}
}
and my build.gradle和我的 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
}
I get below error when I try to execute 'gradle flywayInfo'当我尝试执行“gradle flywayInfo”时出现以下错误
**FAILURE: Build failed with an exception. **失败:构建失败,出现异常。 * What went wrong: Execution failed for task ':flywayInfo'. * 出了什么问题:任务“:flywayInfo”执行失败。
Error occurred while executing flywayInfo Unknown prefix for location (should be either filesystem: or classpath:): :**执行 flywayInfo 位置的未知前缀时发生错误(应该是文件系统:或类路径:)::**
Can someone help me how to provide locations.有人可以帮助我如何提供位置。 As i need to provide multiple locations based on the environments因为我需要根据环境提供多个位置
Thanks谢谢
Did you try just:您是否尝试过:
locations = config.flywayProperties.locations
? ?
I met the same issue caused by the wrong type.我遇到了由错误类型引起的相同问题。 given the String
but String[]
expected.给定String
但预期String[]
。
Please modify like this请像这样修改
locations = "${config.flywayProperties.locations}".split(',')
The next question is why the exception happened as you paste?下一个问题是为什么在粘贴时会发生异常?
Because the coercion from String
to String[]
will result in a wired issue.因为从String
到String[]
的强制会导致有线问题。 For example,例如,
(String[])"filesystem:xxx"
=> [f, i, l, e, s, y, s, t, e, m, :, x, x, x]
hmm, really wired.嗯,确实有线。 so all will be clear when we review the flyway Location code here .所以当我们在这里查看飞行路线位置代码时,一切都会清楚。
all single-word String
will be skipped except :
in [f, i, l, e, s, y, s, t, e, m, :, x, x, x]将跳过所有单字String
除了:
在 [f, i, l, e, s, y, s, t, e, m, :, x, x, x]
the normalizedDescriptor
is the :
that will throw as a signal that is not matching filesystem
or classpath
. normalizedDescriptor
是:
它将作为与filesystem
或classpath
不匹配的信号抛出。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.