Using liquibase file paths via both maven and spring
Solution 1
I commented on Igor's answer, his solution does not seem to work.
In order to solve this, I just pushed a patch to Liquibase: https://github.com/liquibase/liquibase/pull/187. This should be merged in 3.0.6-SNAPSHOT and therefore shortly available in 3.0.6.
With this change, you can now configure SpringLiquibase
with this additional line:
<property name="ignoringClasspathPrefix" value="true" />
Another example/usecase requiring this change can be found here: https://github.com/LateralThoughts/spring-liquibase-extensions.
Solution 2
I think if you change your Maven path from
<changeLogFile>src/main/resources/db/changelog/db.changelog-master.xml</changeLogFile>
to
<changeLogFile>db/changelog/db.changelog-master.xml</changeLogFile>
and update db.changelog-master.xml file for all included files to use path relative to src/main/resources directory, it will fix the problem.
I solved this problem by using the same path to changeLog files in Spring, maven and integration test which call Liquibase. All my changelog files are located under /src/main/resources/db directory in one of the Maven modules within a project.
Maven profile which runs Liquibase, notice path: db/masterChangeLog.xml
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>3.0.2</version>
<executions>
<execution>
<id>*** Install a last major release version of db ***</id>
<phase>process-resources</phase>
<goals>
<goal>update</goal>
</goals>
<configuration>
<changeLogFile>db/masterChangeLog.xml</changeLogFile>
<contexts>dbBuildContext, dmlDevContext</contexts>
<propertyFile>db/liquibase-${user.name}.properties</propertyFile>
<promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>
<logging>debug</logging>
</configuration>
</execution>
db/masterChangeLog.xml file includes these files:
<include file="db/install.xml"/>
<include file="db/update.xml"/>
db/install.xml file includes other changelog files (so does update.xml):
<includeAll path="db/install/seq"/>
<includeAll path="db/install/tab"/>
<includeAll path="db/install/cst"/>
<includeAll path="db/latest/vw" />
Spring context executes the same set of db scripts upon app startup as follows:
<bean id="liquibase" class="liquibase.integration.spring.SpringLiquibase">
<property name="dataSource" ref="baseCostManagementDataSource" />
<property name="changeLog" value="classpath:db/masterChangelog.xml" />
<property name="contexts" value="dbBuildContext, dmlDevContext" />
</bean>
Solution 3
The Maven Plugin has the configuration property changeLogDirectory in recent versions.
Hence setting <changeLogDirectory>src/main/resources</changeLogDirectory>
should achieve what you want.
Solution 4
Specify the logicalFilePath attribute in each databaseChangeLog file. See http://www.liquibase.org/documentation/databasechangelog.html
Alexandr
Updated on June 16, 2022Comments
-
Alexandr almost 2 years
I update scheme and initial data in spring context using the following beean:
<bean id="liquibase" class="liquibase.integration.spring.SpringLiquibase"> <property name="dataSource" ref="dataSource" /> <property name="changeLog" value="classpath:db/changelog/db.changelog-master.xml" /> <property name="dropFirst" value="true" /> </bean>
I also use Maven liquibase plugin to generate sql scripts in order to see what tables are created and etc.
<plugin> <groupId>org.liquibase</groupId> <artifactId>liquibase-maven-plugin</artifactId> <version>2.0.5</version> <configuration> <!--mvn initialize liquibase:updateSQL--> <propertyFile>src/main/resources/db/config/liquibase-gensql-data-access.properties</propertyFile> <changeLogFile>src/main/resources/db/changelog/db.changelog-master.xml</changeLogFile> </configuration> </plugin>
The
db.changelog-master.xml
file includes child liquibase changelog files. The problem, how to refer to them from the master. When I use Spring I have to use the following path via classpath:<include file="classpath:/db/changelog/db.changelog-1.0.xml"/>
When Maven is used, the path is:
<include file="src/main/resources/db/changelog/db.changelog-1.0.xml"/>
I'd like to have the same configuration for both cases. How can I archive it?
-
fbiville over 10 yearsI've tested a similar configuration with Liquibase 3.0.5 and this doesn't work. If I run migrations with SpringLiquibase, all my changesets FILENAME column values will be prefixed with "classpath:" whereas no such prefix is prepended when migrations are run via Maven. Therefore, migrations conflict when using both ways.
-
Syed Shahul almost 10 yearsI am bit confused with <property name="contexts" value="dbBuildContext, dmlDevContext" /> is it not <property name="contexts" value="test, production" /> ? please clarify.
-
fabiohbarbosa over 8 yearsThank you man. Perfect!!!!! My only difference is: <includeAll path="scripts/" relativeToChangelogFile="true"/>
-
Alex Grigorovitch about 8 yearsJust an update: as of liquibase-3.1, the property is now called
ignoreClasspathPrefix
and is true by deault. -
visola over 6 yearsI'm using Liquibase 3.5.3 and its Maven plugin with the same version and using the same path inside Spring and my pom.xml solves the problem!
-
Sir4ur0n over 6 yearsSmall detail that made it work for me: in Maven, don't specify the
src/main/resources
part, otherwise it will be incompatible with Spring. I configureddb/changelog/...
in Maven, andclasspath:db/changelog/...
in Spring (application.properties) and then it worked. -
Ruslan Stelmachenko about 4 years@Rolf This answer now works because of this PR (I think it's yours :-) ). It basically strips
classpath:
prefix before filename comparison, so the fact that FILENAME column values are prefixed withclasspath:
doesn't prevent it to work.