This post describes how to update two databases from maven using liquibase: liquibase using maven with two databases However, when I try the exact same configuration in my p
Does your build need to update 2 databases in one go? An alternative approach is to use Maven profiles as follows:
mvn process-resources
mvn -Pdb2 process-resources
|-- pom.xml
`-- src
`-- main
`-- resources
|-- com
| `-- myspotontheweb
| `-- db
| `-- changelog
| |-- db-changelog-1.0.xml
| `-- db-changelog-master.xml
`-- liquibase.properties
I prefer to use Maven's generate-resources phase to create a liquibase properties file.
Contains two profiles at the end containing the properties associated with the two databases. This solution scales to any number of db environments.
Another item of note is that liquibase uses the populated properties under the targets directory
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.myspotontheweb.db</groupId>
<artifactId>liquibase-demo</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.3.162</version>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>2.0.1</version>
<executions>
<execution>
<phase>process-resources</phase>
<configuration>
<propertyFile>target/classes/liquibase.properties</propertyFile>
<promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>
</configuration>
<goals>
<goal>update</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>db1</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<liquibase.url>jdbc:h2:target/db1/liquibaseTest;AUTO_SERVER=TRUE</liquibase.url>
<liquibase.driver>org.h2.Driver</liquibase.driver>
<liquibase.username>user</liquibase.username>
<liquibase.password>pass</liquibase.password>
</properties>
</profile>
<profile>
<id>db2</id>
<properties>
<liquibase.url>jdbc:h2:target/db2/liquibaseTest;AUTO_SERVER=TRUE</liquibase.url>
<liquibase.driver>org.h2.Driver</liquibase.driver>
<liquibase.username>user</liquibase.username>
<liquibase.password>pass</liquibase.password>
</properties>
</profile>
</profiles>
</project>
This is the template file populated with the profile property values for the specific environment.
# Database credentials
url=${liquibase.url}
driver=${liquibase.driver}
username=${liquibase.username}
password=${liquibase.password}
# Liquibase changelog
changeLogFile=com/myspotontheweb/db/changelog/db-changelog-master.xml
And alternative strategy would be to run the plug-in directly, instead of integrating it into a Maven life-cycle.
mkdir target
mvn liquibase:update
mvn -Pdb2 liquibase:update
Again you are using a profile to control the property settings.
The difference is that the plug-ins settings are controlled by properties set in the profile. No more properties file created under the targets directory for shipment in your jar.
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.myspotontheweb.db</groupId>
<artifactId>liquibase-demo</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.3.162</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>2.0.1</version>
<configuration>
<url>${liquibase.url}</url>
<driver>${liquibase.driver}</driver>
<username>${liquibase.username}</username>
<password>${liquibase.password}</password>
<changeLogFile>src/main/resources/com/myspotontheweb/db/changelog/db-changelog-master.xml</changeLogFile>
<promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>db1</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<liquibase.url>jdbc:h2:target/db1/liquibaseTest;AUTO_SERVER=TRUE</liquibase.url>
<liquibase.driver>org.h2.Driver</liquibase.driver>
<liquibase.username>user</liquibase.username>
<liquibase.password>pass</liquibase.password>
</properties>
</profile>
<profile>
<id>db2</id>
<properties>
<liquibase.url>jdbc:h2:target/db2/liquibaseTest;AUTO_SERVER=TRUE</liquibase.url>
<liquibase.driver>org.h2.Driver</liquibase.driver>
<liquibase.username>user</liquibase.username>
<liquibase.password>pass</liquibase.password>
</properties>
</profile>
</profiles>
</project>