将 Gradle 从 Groovy 转换为 Kotlin DSL(用于 liquibase-gradle-plugin)

Art*_*are 3 groovy liquibase gradle kotlin

这是我在 Groovy DSL 中使用 liquibase-gradle-plugin 的 Gradle 文件:

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath 'org.liquibase:liquibase-core:3.4.1'
        classpath 'org.liquibase:liquibase-gradle-plugin:2.0.1'
        classpath 'org.postgresql:postgresql:42.2.5'
    }
}

apply plugin: 'liquibase'

repositories {
    mavenCentral()
}

dependencies {
    liquibaseRuntime 'org.liquibase:liquibase-core:3.4.1'
    liquibaseRuntime 'org.liquibase:liquibase-gradle-plugin:2.0.1'
    liquibaseRuntime 'org.postgresql:postgresql:42.2.5'
}

task('dev') {
    doLast {
        println "executing dev"
        liquibase {
            activities {
                main {
                    changeLogFile 'C:\\Users\\redacted\\IdeaProjects\\Food\\src\\main\\resources\\changelog.xml'
                    url 'jdbc:postgresql://localhost/mydb'
                    username 'postgres'
                    password 'redacted'
                }
            }
        }
        println "Done running dev."
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我尝试将文件转换为 Kotlin DSL:

plugins {
    id("org.liquibase.gradle") version "2.0.1"
}

repositories {
    mavenCentral()
}

dependencies {
    compile("org.liquibase:liquibase-core:3.4.1")
    compile("org.liquibase:liquibase-gradle-plugin:2.0.1")
    compile("org.postgresql:postgresql:42.2.5")
    add("liquibaseRuntime", "org.liquibase:liquibase-core:3.4.1")
    add("liquibaseRuntime", "org.liquibase:liquibase-gradle-plugin:2.0.1")
    add("liquibaseRuntime", "org.postgresql:postgresql:42.2.5")
}

tasks.register("dev") {
    doLast {
        println("executing dev")
        "liquibase" {
            "activities" {
                "main" {
                    "changeLogFile"("C:\\Users\\redacted\\IdeaProjects\\Food\\src\\main\\resources\\changelog.xml")
                    "url"("jdbc:postgresql://localhost/mydb")
                    "username"("postgres")
                    "password"("redacted")
                }
            }
        }
        println("Done running dev")
    }
}
Run Code Online (Sandbox Code Playgroud)

这一切都在线路上分崩离析"liquibase"。我对 Gradle 不够熟悉 - 在文件的 groovy 版本中,如何liquibase解决?它解决了什么问题 - 它是一个函数吗?我如何让它在 Kotlin 版本中得到同样的解决?然后在此之下,我还需要解决activities, main, changeLogFile, url, username, 和password...

abe*_*ndt 9

尝试将 liquibase 扩展的配置移动到顶层:

plugins {
  id("org.liquibase.gradle") version "2.0.1"
}

...

liquibase {
    activities.register("main") {
        this.arguments = mapOf(
                "logLevel" to "info",
                "changeLogFile" to "src/main/resources/db.changelog.xml",
                "url" to "jdbc:postgresql://localhost/dbName",
                "username" to "userName",
                "password" to "secret")
    }
}

tasks.register("dev") {
   // depend on the liquibase status task
   dependsOn("update")
}
Run Code Online (Sandbox Code Playgroud)