3

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

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

谢谢

4

2 回答 2

0

您是否尝试过:

 locations = config.flywayProperties.locations

?

于 2015-04-17T20:02:37.783 回答
0

我遇到了由错误类型引起的相同问题。鉴于StringString[]预期。

请像这样修改

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

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

因为强制 from StringtoString[]将导致有线问题。例如,

(String[])"filesystem:xxx"
=> [f, i, l, e, s, y, s, t, e, m, :, x, x, x]

嗯,确实有线。所以当我们在这里查看飞行路线位置代码时,一切都会清楚。

除了[f, i, l, e, s, y, s, t, e, m, :, x, x, x]以外的所有单词String都将被跳过:

thenormalizedDescriptor:作为不匹配的信号抛出filesystemor classpath

于 2020-04-19T01:57:12.133 回答