不使用指定上下文的Gradle Liquibase插件

不使用指定上下文的Gradle Liquibase插件,gradle,liquibase,Gradle,Liquibase,我们有一个使用Liquibase的Gradle项目,我们的构建文件有: buildscript { repositories { mavenCentral() } dependencies { classpath 'org.liquibase:liquibase-gradle-plugin:1.1.1' classpath 'org.liquibase:liquibase-core' } } apply plugi

我们有一个使用Liquibase的Gradle项目,我们的构建文件有:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'org.liquibase:liquibase-gradle-plugin:1.1.1'
        classpath 'org.liquibase:liquibase-core'
    }
}

apply plugin: 'liquibase'
然而,当我们试图通过以下方式更新我们的项目时:

gradle update -Dliquibase.contexts=foobar
(使用
--上下文也尝试过)
它似乎忽略了指定的上下文,而是运行所有变更集

例如:

changeSet(author: 'me', id: 'someId1', context: 'somethingElse') { // This runs, but shouldn't
// ... 
changeSet(author: 'me', id: 'someId2', context: 'foobar') { // Should only run this
这个项目在某一点上是分叉的,所以我们可能误解了文档(,),但看起来这应该是可行的


我们需要不同的插件/版本吗?我们称之为错误吗?

Derp,看起来您需要在构建文件中手动获取上下文:

main {
    if (project.hasProperty('contexts')) {
        contexts contexts
    }
    url 'someurl'
    username 'username'
    password 'pass'
}
然后通过以下方式传递:

gradle update -Pcontexts=schema

您应该在任务中定义上下文

task('liquibase_dev') << {

liquibase {
    activities {
        main {
            changeLogFile changeLog
            url 'jdbc:postgresql://localhost:5432/test'
            username 'postgres'
            password 'admin'
            contexts 'DEV'
        }
    }
}
只有第一个变更集将被执行

更新的插件(2.0.3),同样的问题和稍微不同的解决方案,因为我保留了一个默认上下文

liquibase.gradle(代码段):

gradle.properties(代码段):

因此,现在可以安全地拨打:

./gradlew liquibaseUpdate # to apply contexts=dev
以及:

./gradlew :liquibase_dev update 
if (!project.hasProperty("contexts")) {
    project.ext.contexts = "dev"
}

liquibase {
    activities {
        main {
            driver "${datasource_driver}"
            url "${datasource_url}"
            username "${datasource_username}"
            password "${datasource_password}"
            changeLogFile "src/main/resources/db/changelog/master.xml"
            defaultSchemaName ""
            logLevel "info"
            contexts contexts
        }
    }
}

tasks.liquibaseUpdate.dependsOn(tasks.classes)
liquibaseTaskPrefix=liquibase
./gradlew liquibaseUpdate # to apply contexts=dev
./gradlew liquibaseUpdate -Pcontexts=test # to apply contexts=test