shubham4194
shubham4194

Reputation: 81

Read liquibase change log properties from external property file with maven

I want to read Liquibase change log properties from an external property file. I do not want to define them in the databasechangelog.xml in property tag as I want different parameters for different environments. My external property file will be chosen according to the profile I chose for the maven plugin. E.g. CREATE OR REPLACE SYNONYM ${schema1}.myTable FOR ${schema2}.myTable; I want these parameters ${schema1} and ${schema2} to picked from an property file. Is this possible

Edit: According to @bilak comment I tried this 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 config parameters are read correctly but parameter.testcolumn is not used

mvn liquibase:update -Pprofile

Upvotes: 0

Views: 2860

Answers (1)

bilak
bilak

Reputation: 4954

You can use file liquibase.properties (default name) and put there variables like:

parameter.schema1=yourSchema1 parameter.schema2=yourSchema2

edit: That option doesn't work with liquibase-maven-plugin but there could be workaround with 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>

if you execute then mvn exec:exec -Pliquibase it should replace your placeholders with parameters from liquibase.properties.

edit 2019/07 Now you can use property file to load properties from

Upvotes: 2

Related Questions