flyway gradle插件与groovy环境

时间:2015-04-17 18:58:51

标签: gradle flyway gradle-plugin

我正在尝试自定义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位置的未知前缀时出错(应该是filesystem:或classpath :) :: **

  

有人可以帮助我提供位置。因为我需要根据环境提供多个位置

由于

2 个答案:

答案 0 :(得分:0)

您是否尝试过:

 locations = config.flywayProperties.locations

答案 1 :(得分:0)

我遇到了由错误类型引起的相同问题。给定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不匹配的信号抛出。