【问题标题】:flyway gradle plugin with groovy environments带有 groovy 环境的 flyway gradle 插件
【发布时间】:2015-06-24 18:53:15
【问题描述】:

我正在尝试自定义 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时发生错误位置前缀未知(应该是文件系统:或类路径:)::**

谁能帮助我如何提供位置。因为我需要根据环境提供多个位置

谢谢

【问题讨论】:

    标签: gradle flyway gradle-plugin


    【解决方案1】:

    你试过了吗:

     locations = config.flywayProperties.locations
    

    ?

    【讨论】:

      【解决方案2】:

      我遇到了由错误类型引起的相同问题。给定String,但预期String[]

      请这样修改

      locations = "${config.flywayProperties.locations}".split(',')
      

      下一个问题是为什么在粘贴时会发生异常?

      因为从StringString[] 的强制转换将导致有线问题。例如,

      (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, x] 中的 : 之外,所有单字 String 将被跳过

      normalizedDescriptor:,它将作为与filesystemclasspath 不匹配的信号抛出。

      【讨论】:

        猜你喜欢
        • 2014-04-03
        • 2012-10-20
        • 2021-11-22
        • 2014-05-21
        • 2015-10-08
        • 2014-09-19
        • 1970-01-01
        • 2015-04-04
        • 1970-01-01
        相关资源
        最近更新 更多