Search code examples
gradlekotlinflywaygradle-kotlin-dsl

Flyway and gradle kotlin dsl


I'm migrating from Gradle to Gradle Kotlin DSL, and I have a question. Have

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

In Gradle.

How would you look in Kotlin DSL?


Solution

  • The code in the block is almost exactly the same in Kotlin as in Groovy, with two exceptions for what you have above:

    • Use double-quotes instead of single-quotes for the strings.
    • Use arrayOf instead of [...] for the array for the locations property.

    In other words it would look as follows:

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

    Bear in mind that for the build file to understand the flyway function (and for the IDE to give you intellisense for what options are available in the block, etc.) you need to apply the Flyway plugin using the Gradle Plugins DSL, as follows at the top of your build.gradle.kts file:

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