下面是我在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."
}
}下面是我将该文件转换为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")
}
}这一切都在"liquibase"这一行分崩离析。我对Gradle还不够熟悉--在groovy版本的文件中,liquibase是如何解析的?它解析的是什么-它是一个函数吗?我如何让它在Kotlin版本中得到同样的解决?然后在此基础上,我还需要解析activities、main、changeLogFile、url、username和password...
发布于 2019-06-14 05:56:42
尝试将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")
}https://stackoverflow.com/questions/56588637
复制相似问题