Flyway 和 gradle kotlin dsl

Flyway and gradle kotlin dsl

我正在从 Gradle 迁移到 Gradle Kotlin DSL,我有一个问题。 有

flyway {
    url = System.getenv ('DB_URL')
    user = System.getenv ('DB_USER')
    password = System.getenv ('DB_PASSWORD')
    baselineOnMigrate = true
    locations = ["filesystem: resources / db / migration"]
}

在Gradle.

您如何看待 Kotlin DSL?

该块中的代码在 Kotlin 中与 Groovy 中的代码几乎完全相同,除了上面的两个例外:

  • 对字符串使用 double-quotes 而不是 single-quotes。
  • 使用 arrayOf 而不是 [...] 作为 locations 属性 的数组。

换句话说,它将如下所示:

flyway {
    url = System.getenv("DB_URL")
    user = System.getenv("DB_USER")
    password = System.getenv("DB_PASSWORD")
    baselineOnMigrate = true
    locations = arrayOf("filesystem: resources / db / migration")
}

请记住,要让构建文件理解 flyway 函数(并让 IDE 为您提供块中可用选项的智能感知等),您需要使用 Gradle Plugins DSL 应用 Flyway 插件,如下在 build.gradle.kts 文件的顶部:

plugins {
    id("org.flywaydb.flyway") version "5.2.4"
}