将flyway.target和flyway.initVersion属性传递给flywayMigrate gradle任务导致强制转换异常错误

时间:2013-08-07 09:23:46

标签: gradle flyway

尝试将目标属性传递给FlywayMigration gradle任务

gradle flywayMigrate -d -Pflyway.target='1.0.0'

gradle flywayMigrate -d -Pflyway.target=1.0.0

flyway {
url = 'jdbc:h2:file:target/foobar'
user = 'sa'
target = '1'}

以org.codehaus.groovy.runtime.typehandling.GroovyCastException

失败
09:08:25.855 [ERROR] [org.gradle.BuildExceptionReporter] Caused by: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '1.0.0' with class 'java.lang.String' to class 'com.googlecode.flyway.core.api.MigrationVersion'

使用的版本和平台:

'com.googlecode.flyway:flyway-gradle-plugin:2.2'

gradle -version
Gradle 1.6
Gradle build time: Tuesday 07 May 2013 9:12:14 AM
Groovy: 1.8.6
Ant: Apache Ant(TM) version 1.8.4 compiled on May 22 2012
Ivy: 2.2.0
JVM: 1.7.0_05 (Oracle Corporation 23.1-b03)
OS: Mac OS X 10.8.3 x86_64

这似乎会影响何时尝试设置两个属性:

  • initVersion

仔细看看这两种方法都覆盖了接受不同类型作为参数的setter:

Sets the version to tag an existing schema with when executing init.
Parameters:
initVersion The version to tag an existing schema with when executing init. (default: 1)
740 
741     public void setInitVersion(MigrationVersion initVersion) {
742         this.initVersion = initVersion;
743     }


Sets the version to tag an existing schema with when executing init.
Parameters:
initVersion The version to tag an existing schema with when executing init. (default: 1)
749 
750     public void setInitVersion(String initVersion) {
751         this.initVersion = new MigrationVersion(initVersion);
752     }

然而,似乎在gradle目标设置中,当在这两个方法上调用setter时,那些优先级groovy与正确的覆盖类型不匹配:

 /**
 * Sets this property on this Flyway instance if a value has been defined.
 * @param flyway The Flyway instance.
 * @param property The property to set.
 */
private void propSet(Flyway flyway, String property) {
    def value = prop(property);
    if (value != null) {
        flyway[property] = value;
    }
}
Flyway已经开通了{p> Issue 574 也许他们可以分享一些关于正确用法的更多见解,以设置上述属性。

0 个答案:

没有答案