Liquibase模块和Spring Boot Project中的变量

问题描述

我在项目中使用liquibase,这是我的配置文件之一:

group 'com.project.test'
version '0.1.0'

buildscript {
    dependencies {
        classpath "org.liquibase:liquibase-gradle-plugin:${liqubasePluginVersion}"
        classpath "gradle.plugin.com.avast.gradle:gradle-docker-compose-plugin:${gradleDockerComposePluginVersion}"
    }
}

apply plugin: 'java'
apply plugin: 'org.liquibase.gradle'
apply plugin: 'com.avast.gradle.docker-compose'

dependencies {
    liquibaseRuntime "org.liquibase:liquibase-core:${liquibaseCoreversion}"
    liquibaseRuntime "org.postgresql:postgresql:${postgresqlVersion}"
}

liquibase {
    activities {
        main {
            def file = new File("${projectDir}/liquibase.properties")
            if (file.exists()) {
                def props = new Properties()
                InputStream is = new FileInputStream(file)
                props.load(is)
                is.close()

                changeLogFile props['changeLogFile']
                outputFile 'liquibase/sql-migration-bundle.sql'
                url props['url']
                username props['username']
                password props['password']
            } else {
                println "Add ${projectDir}/liquibase.properties if you want use liquibase plugin"
            }
        }
        dockerPostgres {
            changeLogFile "${projectDir}/changelog/changelog-master.yml"
            url 'jdbc:postgresql://localhost:5555/test'
            username 'test'
            password 'test'
        }
        runList = 'main'
    }
}

task localUpdate(dependsOn: "composeUp") {
    doFirst {
        liquibase.setProperty("runList","dockerPostgres")
    }
    finalizedBy update
}

task localDropAll(dependsOn: "composeUp") {
    doFirst {
        liquibase.setProperty("runList","dockerPostgres")
    }
    finalizedBy dropAll
}

这是我的“ liquibase”模块的build.gradle:

padding-bottom

我有两个不同的模式名称一个用于生产的“ prod”和一个用于测试的“ test”。 在测试和部署应用程序时,是否可以在application.yml或build.gradle中设置一个变量来更改名称

P.S。我的Spring应用程序还有两个不同的配置文件-“ prod”和“ test”

解决方法

您当然可以在liquibase的运行时添加properties(可以从gradle,直接从命令行等传递过来)。

例如,您可以在CLI上调用liquibase: liquibase -Durl =更新