1

I tried to use multiple databases with liquibase maven plugin. I followed the link : liquibase using maven with two databases

However when I try to run it I get an error "[ERROR] Failed to execute goal org.liquibase:liquibase-maven-plugin:3.5.3:update (default-cli) on project liquibase-helloworld-demo: The database URL has not been specified either as a parameter or in a properties file."

Please find my pom below :

<build>
    <finalName>liquibase-helloworld-demo</finalName>
    <plugins>
        <plugin>
            <groupId>org.liquibase</groupId>
            <artifactId>liquibase-maven-plugin</artifactId>
            <version>3.5.3</version>
            <executions>
                <execution>
                    <id>id1</id>
                    <phase>process-resources</phase>
                    <configuration>
                        <changeLogFile>
                            ${basedir}/src/main/resources/liquibase/changelog1.xml
                        </changeLogFile>
                        <driver>com.mysql.jdbc.Driver</driver>
                        <url>jdbc:mysql://localhost:3306/liquibase-test</url>
                        <username>*****</username>
                        <password>*****</password>
                    </configuration>
                    <goals>
                        <goal>update</goal>
                    </goals>
                </execution>
                <execution>
                    <id>id2</id>
                    <phase>process-resources</phase>
                    <configuration>
                        <changeLogFile>
                            ${basedir}/src/main/resources/liquibase/changelog2.xml
                        </changeLogFile>
                        <driver>com.mysql.jdbc.Driver</driver>
                        <url>jdbc:mysql://localhost:3306/liquibase-test</url>
                        <username>*****</username>
                        <password>*****</password>
                    </configuration>
                    <goals>
                        <goal>update</goal>
                    </goals>
                </execution>
            </executions>
            <dependencies>
                <dependency>
                    <groupId>mysql</groupId>
                    <artifactId>mysql-connector-java</artifactId>
                    <version>5.1.9</version>
                </dependency>
            </dependencies>
        </plugin>
    </plugins>
</build>

Can you please help? Thanks in Advance.

Thanks Rahul Saraswat

2 Answers2

1

We have used postgres and mysql in our spring boot application with gradle as following. check it for helping.

spring:
    datasource:
        initialize: false
    db1Datasource:
        jdbcUrl: jdbc:postgresql://localhost:5432/db1
        driverClassName: org.postgresql.Driver
        username: postgres
        password: root
        poolName: HikariCP-db1-pool
        liquibase:
            change-log: classpath:database/db1/changelog.groovy
            contexts: dev
    db2Datasource:
        jdbcUrl: jdbc:mysql://localhost:3306/db2
        driverClassName: com.mysql.jdbc.Driver
        username: root
        password: root
        poolName: HikariCP-db2-pool
        liquibase:
            change-log: classpath:database/db2/changelog.groovy
            contexts: dev
0

The error You mentioned appeared because your maven-liquibase-plugin is configured to be run with specifying lifecycle phase and NOT plugin goal. You should run NOT 'mvn liquibase:update' command BUT 'mvn process-resources' or upper one e.g. 'mvn compile'.

In order to run a goal in the format 'plugin-prefix:goal' (like: 'mvn liquibase:update') You should add additional 'configuration' section to plugin, besides these two within execution sections. Please take a look at example below:

            <plugin>
            <groupId>org.liquibase</groupId>
            <artifactId>liquibase-maven-plugin</artifactId>
            <version>4.19.0</version>

            <configuration>
                <url>
                    jdbc:sqlserver://${db_1.server};databaseName=${db_1.name};integratedSecurity=true;encrypt=false;
                </url>
                <changeLogFile>/path/to/changelog_1.xml</changeLogFile>
                <driver>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver>
            </configuration>

            <executions>
                <execution>
                    <id>db_1.exec</id>
                    <phase>process-resources</phase>
                    
                    <configuration>
                        <changeLogFile>/path/to/changelog_1.xml</changeLogFile>
                        <driver>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver>
                        <url>
                            jdbc:sqlserver://${db_1.server};databaseName=${db_1.name};integratedSecurity=true;encrypt=false;
                        </url>                           
                    </configuration>
                    <goals>
                        <goal>update</goal>
                    </goals>
                </execution>

                <execution>
                    <id>db_2.exec</id>
                    <phase>process-resources</phase>

                    <configuration>
                        <changeLogFile>/path/to/changelog_2.xml</changeLogFile>
                        <driver>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver>
                        <url>
                            jdbc:sqlserver://${db_2.server};databaseName=${db_2.name};integratedSecurity=true;encrypt=false;
                        </url>
                    </configuration>
                    
                    <goals>
                        <goal>update</goal>
                    </goals>
                </execution>
            </executions>
            
            <dependencies>
                <dependency>
                    <groupId>com.microsoft.sqlserver</groupId>
                    <artifactId>mssql-jdbc</artifactId>
                    <version>${mssql-jdbc.version}</version>
                </dependency>
            </dependencies>
            
        </plugin>

The only restriction in this case is that the only 1 database will be updated when running 'mvn liquibase:update'.

Commands 'mvn process-resources' or 'mvn compile' will do updates for both.