首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将Gradle从Groovy转换为Kotlin DSL (用于liquibase gradle-plugin)

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

Stack Overflow用户
提问于 2019-06-14 05:13:12
回答 1查看 1.2K关注 0票数 4

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

代码语言:javascript
复制
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."
    }
}

下面是我将该文件转换为Kotlin DSL的尝试:

代码语言:javascript
复制
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")
    }
}

这一切都在"liquibase"这一行分崩离析。我对Gradle还不够熟悉--在groovy版本的文件中,liquibase是如何解析的?它解析的是什么-它是一个函数吗?我如何让它在Kotlin版本中得到同样的解决?然后在此基础上,我还需要解析activitiesmainchangeLogFileurlusernamepassword...

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-06-14 05:56:42

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

代码语言:javascript
复制
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")
}
票数 11
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56588637

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档