【问题标题】:Read liquibase change log properties from external property file with maven使用 maven 从外部属性文件读取 liquibase 更改日志属性
【发布时间】:2018-12-10 08:15:35
【问题描述】:

我想从外部属性文件中读取 Liquibase 更改日志属性。我不想在属性标签的 databasechangelog.xml 中定义它们,因为我想要不同环境的不同参数。我的外部属性文件将根据我为 Maven 插件选择的配置文件进行选择。 例如。创建或替换同义词 ${schema1}.myTable FOR ${schema2}.myTable; 我希望从属性文件中选择这些参数 ${schema1} 和 ${schema2}。这可能吗

编辑:根据@bilak 的评论,我试过这个 pom.xml:

<plugin>
    <groupId>org.liquibase</groupId>
    <artifactId>liquibase-maven-plugin</artifactId>
    <version>3.4.2</version>
    <configuration>
        <propertyFile>${basedir}/../environments/${build.profile.id}/liquibase.properties</propertyFile>
        <changeLogFile>${basedir}/src/main/resources/sql/db-changelog-master.xml</changeLogFile>
    </configuration>
</plugin>

liquibase.properties:

driver=oracle.jdbc.OracleDriver<br>
url=xxxxx<br>
username=xxxxxx<br>
password=xxxxxx<br>
parameter.testcolumn=test_column

db 配置参数被正确读取但 parameter.testcolumn 未被使用

mvn liquibase:update -Pprofile

【问题讨论】:

    标签: liquibase


    【解决方案1】:

    您可以使用文件 liquibase.properties(默认名称)并将变量放在那里:

    parameter.schema1=yourSchema1 parameter.schema2=yourSchema2

    编辑: 该选项不适用于liquibase-maven-plugin,但可能有maven-exec-plugin 的解决方法:

        <profiles>
            <profile>
                <id>liquibase</id>
                <build>
                    <plugins>
                        <plugin>
                            <groupId>org.codehaus.mojo</groupId>
                            <artifactId>exec-maven-plugin</artifactId>
                            <version>1.6.0</version>
                            <configuration>
                                <executable>java</executable>
                                <arguments>
                                    <argument>-classpath</argument>
                                    <classpath/>
                                    <argument>liquibase.integration.commandline.Main</argument>
                                    <argument>--defaultsFile=src/main/resources/database/liquibase.properties</argument>
                                    <argument>updateSQL</argument>
                                </arguments>
                            </configuration>
                        </plugin>
                    </plugins>
                </build>
            </profile>
        </profiles>
    

    如果你执行然后mvn exec:exec -Pliquibase 它应该用来自liquibase.properties 的参数替换你的占位符。

    edit 2019/07 Now 您可以使用属性文件从

    加载属性

    【讨论】:

    • liquibase 文档说:参数值按以下顺序查找:1.作为参数传递给您的 Liquibase 运行器(有关如何传递它们,请参阅 Ant、command_line 等文档)2。作为 JVM 系统属性 3.在 DatabaseChangeLog 文件本身的参数块( Tag)中。它没有说明 liquibase.properties。该文件用于各种目标使用的参数
    • 试试吧,你可以查看here 了解实现细节。它没有记录在案。
    • 我在属性文件中添加了 parameter.testcolumn=test_column 用作 ${testcolumn} 不起作用
    • 分享你执行 liquibase 的配置和命令。
    • 添加了 pom.xml 和 liquibase.properties
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-25
    • 2017-01-24
    • 1970-01-01
    • 2020-05-10
    • 1970-01-01
    相关资源
    最近更新 更多